Measuring Hue in selected area from JPG photos

I have many photos of birds. I’m working on developing a way to separate species using the hue of a selected area, such as the flank, or back feathers. I want to select an area and then find the average hue “angle” for that area. I have figured out how to get the RBG averages for a selection, but it would be much simpler to be able to compare hues.
I’ve combed the manual and this forum but can’t find anything that seems to address this (or at least that I can understand!)

Thanks very much for any guidance on this!!

Hello Tom -

Run Image > Type > HSB Stack (to convert your image to HSB
space) and run your measurement on the “Hue” slice of the resulting
three-channel stack.

Thanks, mm

Thanks very much for the fast response.
I had tried that before but all of the color measurement tools I know about give me an error message stating that they “only work with RBG files.”
Are there specific tools that would give me an average hue for a selection, once I’ve split up the channels?
(very sorry if I’m missing something obvious!!)

Hello Tom -

Yes, the regular grayscale measurement tools will give you what you
want.

The slices of an HSB stack are just grayscale images in which the
grayscale “intensity” is the numerical value of hue, etc. So take your
“Hue” slice, select the ROI you wish to analyze, and run Measure.
The “Mean” value in the results table will be your average hue.

As you note, hue is an angular variable. Therefore, somewhere
off in “red” land it wraps around from 255 back to 0. The mean
“intensity” doesn’t know this, so averaging a magenta / red / yellow
region that ought to give you an average reddish hue near 0 or 255,
could give you a misleading “cyan” hue around 127. This is generally
not a problem, but could (and does) happen in practice, so check
your specific use case.

Thanks, mm

Thanks again very much for your help with this!

I’ll be measuring a wide range of colors, so your description of the issue of colors not averaging properly is concerning. Would this issue be a problem with a wide range of colors?
Is there a way to compensate for it? Seems like the results could be unpredictable, possibly?

Also, (and thanks again for your kind responses…and feel free to say “enough!” ) is there a way in ImageJ/Fiji to “straighten out” the color space if it’s been skewed by a blue shift or some other color imbalance.
In Photoshop, for example, I can use the LEVELS eyedropper tools to adjust the range using a black and a white area. I’m assuming this does some math to balance the range based on what should be 0,0,0 or 255,255,255 but has been unbalanced slightly.
This could be an issue with our samples also.

Hello Tom -

If you need to average a single ROI that contains a wide range of
colors – the whole rainbow, so to speak – this will be a tricky issue
to deal with. (But I have the sense that you don’t want or need to
do this – that individual ROIs will be more-or-less the same hue
throughout.)

So, for limited-hue-range ROIs, this will only be a problem when
you’re averaging over an ROI whose hue is in the red region where
the hue angle wraps around from 360 back to 0 degrees.

It would be relatively straightforward to write a script (or plugin)
that correctly calculates a “wrap-around” angular hue average.

If you don’t wish to go the script route, you could, for ROIs that
are reddish, first rotate the hue, calculate the average, and then
rotate back. I don’t believe that ImageJ has a built-in hue-rotation
function, but this HueRotation.txt macro seems to be blessed by
the ImageJ gods.

(To automate this so that you don’t have to flag reddish ROIs by
hand, I suspect that you could rotate-average-derotate for angles
of 0 (no-op), 120, and 240 degrees, and then use the average hue
that wins a best two-out-of-three vote as your result.)

I’m not aware of any ImageJ tool that will automatically and
quantitatively perform a color correction for you. However, you
can run Image > Adjust > Color Balance... by hand
on your RGB image before converting to hue space.

Thanks, mm

Thanks again, very much, for your help with this.
I’ll doing some experiments now and, if OK, may check back with some questions later…