Help: measure width, length and color of fruits




The pictures I am working with have images of 30 fruits. From each fruit image, I need to collect data such as area, diameter, length, center of mass, and color. I have been able to get the area of each fruit by converting the image to 8-bit, adjust threshold and measure the areas. However, I don’t know how to get the other data from each fruit image (length, width and color). Don’t have ample experience working with image J. I will appreciate all the help I can get. Thanks!


Is this a gray-scale image? You should be able to get width/diameter, length, and center of mass using the measure tool; the same way you get area. Go to Analyze > Set Measurements... and take a look at the different options you can choose. I believe the ones you want are “Center of mass” and “Bounding rectangle”. If it is a gray-scale image, you can also get the “Mean gray value”, “Standard deviation”, “Modal gray value”, “Min & max gray value”, and “Median”.


Thanks Andrew,

Your information is helpful. With “bounding rectangle” I am able to get the width and the length. I still need the information of color. The original is a color image, I changed it to 8 bit for gray scale and being able measure the fruits. However, when selecting the options of gray value (mean gray value, modal gray value, min, max) I got only zeros. Am I doing something wrong? Also, is there any script that I can use to automate the measurements? I have 100 pictures more to go through!.

I am uploading an example of the pictures to be analyzed. The black circles in the sides of the picture are the references placed when the pictures were taken. Black circles have a diameter= 1 inch.


Try here


I am not able to reproduce the all-zeros effect you described. Could you describe a bit more about what you are doing when it happens; if it is still happening?

Similar to what is suggested in the topic yempski linked to, you can use Image > Color > Split Channels to separate the color image into 3 gray-scales; one each for red, green, and blue intensities. You could then use the gray value measurements on each of the 3 channels to represent the colors.


Hi Andrew,

Thanks for your information. I think that I was getting zeros previously was because I was not splitting the channels.
Now I have split the channels to get the gray-scales. For getting the gray values from each channel I converted them to 8 bit image, and apply the threshold. I could get data from the blue and green channels. For the blue most of the values tend to be 255 (I believe that’s black, so meaning that the blue color is saturated in my samples?, I am getting lost in this topic) for green the values are from 28 to 57. However, when I was trying to apply the threshold for the red channel, I noticed that it was trouble to select only the fruits and not the shadows. In most of the cases I couldn’t get to select the whole fruits without getting the shadow noise. So, I couldn’t get gray values for that channel.

On the other hand, I have noticed that if I select the individual fruits with the multi-point tool, and then go to analyze/color histogram I go the count of the fruits total values for each channel, and averages. Those values are different from the ones I got for green and blue channels when I split the channels. What method would be best? If color histogram is the best option,then is there a method to select the fruits without select one by one?


Yes, 255 means it is fully saturated in that channel. I am afraid this is where I don’t know as much. How are you using the multi-point tool to select the entire fruits? As far as I know, the multi-point tool selects only individual points, not areas.


Okay, so I had some time to take another look. To clarify, 255 does mean fully saturated but it should correspond to white, not black. Black has an RGB value of (0,0,0).

Based on what I can tell, it seems that the blue channel is easiest to threshold. What you could do is use that to create a mask. To me, it seems that 0 to 120 is a good range to select the objects in the image. Once you have converted that to binary, you will probably want to remove noise. There are a lot of different ways to do this. However, your images are pretty clear so simply using the paintbrush tool to manually fill-in and remove the necessary pixels should be reasonable. If you really want an automated way, you can use Process > Binary > Close. You will probably want to try a few different settings (Process > Binary > Options...) to see which gives you the best results. I usually set Count to 4. Based on a quick test, you are probably looking at somewhere between 5 and 20 Iterations to fill the missing pixels. There are a few ways to apply the mask. The simplest is to run Edit > Invert and then, for each channel, Process > Image Calculator.... Set the original channel as the first image and the mask as the second. Select subtract as the operation. This should produce an image with everything but the objects set to 0 (i.e. complete absence of the color associated with the channel). Below is an example resulting image based on the red channel.


Thanks Andrew!. Let me revisit the image and the steps you mentioned before. I am getting beyond my knowledge in image J. I will try it and let you know how was the process.


I am getting beyond my knowledge in image J.

Please increase your knowledge by studying the ImageJ-user guide:

Good luck