3

I have a folder with many images with different backgrounds. I have got requirement to sort these images on the basis of background color.

Can I make a java program to read the folder and each image file in there, and decide the image of each file? please share options.

2
  • You have the requirement to sort the images, does that mean to sort them in your file manager like Windows Explorer? Commented Sep 23, 2010 at 15:29
  • @Mstodd : I will identify the image background color and put then specific folder. If the image has black background, It should be placed into folder Black. Commented Sep 23, 2010 at 15:33

2 Answers 2

2

Yes, it is possible. You can load images with ImageIO.

BufferedImage img = ImageIO.read(imageFile); int rgb = img.getRGB(x,y); Color color = new Color(rgb); 

But you have to create an algorithm that finds out which color is the backround color. It depends on the kind of images.

Sign up to request clarification or add additional context in comments.

Comments

2

So, not knowing what your images really look like, you may want to average as much of the background as you can to come up with a good representation of the background color.

I would consider a couple things:
* Read in the pixels of each of the four edges. If there's little variance in the pixel color, then you may be done, just take the average.
* Do the same, but also read in lines from the edge to the middle until you hit a pixel that has a rather different color than your running average. Do this for all edges.

Those would be the cheapest things that I can think of to cover variances in background color. Depending on the images you're working with, you may have to get fancier.

A BufferedImage should get you your image data.

Mark

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.