Jump to content

How to determine the average color over a selection


Recommended Posts

I am trying to determine the "redness" of a person's palm and sole by

evaluating digital images using L*a*b values. Is there a way in

Photoshop or another program to average the L*a*b values over a

selected area (eg., entire palm) rather than just a 3 pixel area

(dropper)?

Thanks

Paul

UW School of Pharmacy

Link to comment
Share on other sites

Well, one way would be to reduce the image resolution drastically (on a COPY of the image file!) so that the palm or sole is reduced to a single pixel (or a 3x3 array). In resampling the image Photoshop will come up with an 'average' value from all the previous pixels, which you can then measure with the eyedropper.

 

Actually you'd probably want the final pixel to be just slightly smaller than the sole/palm, to avoid picking up any color or brightness values, in the 'average', from the surrounding background.

 

There's also a 'pixellate' filter that will do roughly the same thing (but creating bigger squares instead of reducing the image file size).

 

In either case you'll have to experiment a bit (with liberal use of the "undo" command) to find settings for image size or pixel size that work best for the image you're starting with.

Link to comment
Share on other sites

I just tested Emre's suggested technique - but while the "strong gaussian blur" only CHANGES the pixels within the selected area, it does pick up tones/colors from outside the selected area (but within the blur radius) as part of the blurred tone, which could throw off color measurements.

 

See example<div>004NxK-11002584.jpg.dc2579c5cda71db616e884bff1eda4b2.jpg</div>

Link to comment
Share on other sites

Example shows the back of a hand, not the palm, but the principle applies.

 

I used the 'pixellate/mosaic' filter over that part of the image - each 'pseudopixel' or 'superpixel' created averages the tones within it. You can vary the size of the superpixels when applying the filter to get the best fit to your image. A 10x10 array will average 1000 pixels into 10, cutting the number of measurements you need to make by a factor of 100. Photoshop will do at least 95% of the work for you.

 

As with Emre's technique the pixels near the edge pick up some contamination from colors/tones outside the hand - so assume they are 'bad data'.

Link to comment
Share on other sites

Andy is certainly on the ball, but I am not going to be trumped by him :P

<p>

I tested my method too and he is right. I have good news and I have bad news. The good news is that I found a way to avoid the problem. The bad news is that the selection has to be rectangular unless you use a supporting application. Make your selection using the "rectangular marquee" tool. Copy it and paste it into a new document. Apply Gaussian blur with maximum radius. This time fringing won't occur because there is no fringe :)

<p>

There is a better way if you have MATLAB. Save your selection (ensuring the rest is transparent) as a PNG or TIFF into a separate file and run the following commands in MATLAB:

<p><hr>

<code>

img=imread('selection.png');<br>

vec=reshape(img,prod(size(img))/3,3);<br>

ind=find(sum(vec,2));<br>

average(vec(ind,:));<br>

</code><hr>

N.B.: You might need to change directory first with CD.

<p>

What we do here is to convert the image matrix into a vector. Then we discard the background (zeros in the matrix) and find the average of what is left. The 'average' function does not exist -- you have to define it to implement your definition of "average".

Link to comment
Share on other sites

Andy and Emre, you two are amazing. Thanks very much for your excellent ideas. I think that, with no MATLAB experience, I will try the Photoshop export/Gaussian blur that Emre suggests. The MATLAB online manual suggests that the vector used is RGB, which raises another issue (posted as a new thread) about the "best" measure of redness, and whether one scale is better than another (eg., linear) for making statistical comparisons of "redness". Thank you very much.

Paul

Link to comment
Share on other sites

Perhaps I should have touched upon that. You can convert between RGB and HSV by using <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/rgb2hsv.shtml"><code>rgb2hsv</code></a> and <a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hsv2rgb.shtml"><code>hsv2rgb</code></a>. A similar conversion is possible between <a href="http://www.tsi.enst.fr/tsi/enseignement/ressources/mti/correl_couleur/sourcematlab.html#RGB2LAB">RGB and Lab</a>. Now you can take your pick. Obviously you still need to define a metric!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...