Azzera filtri
Azzera filtri

Compare color of images

11 visualizzazioni (ultimi 30 giorni)
Elvin
Elvin il 19 Dic 2013
Modificato: Image Analyst il 24 Nov 2020
I have two standard shades of green.
I also have a test image ( a leaf with black background).
Can you show me how to compare the test image with the 2 standard images and determine where the test image falls closer, in terms of color, among the 2 standard images.
thank you.

Risposta accettata

Image Analyst
Image Analyst il 19 Dic 2013
I know we've talked about this before, a few months ago or so. First segment out the green leaf - get a binary image that is true where the leaf is and false where the leaf isn't. For example use the green mask like Walter showed you. Then the most widely used method in the color industry is to calculate the "Delta E" (which is the color difference). You convert RGB into LAB and then calculate the Euclidean distance between the two points in LAB color space. At least that's the simplest which is probably okay for you. Remember we talked about using a color checker passport to calibrate your images. Otherwise you're just using "book formulas" - which might be okay if you just want to find out which standard is closest. But if you ever want to graduate to a fully calibrated system, you'll have to use a standard such as the Color Checker Passport or the Munsell soil chart or the X-rite Color checker.
  8 Commenti
Image Analyst
Image Analyst il 19 Dic 2013
Looks right, except that you don't need or use inleaf_pixels.
Elvin
Elvin il 19 Dic 2013
Thank you very much for the help sir. :)

Accedi per commentare.

Più risposte (2)

Walter Roberson
Walter Roberson il 19 Dic 2013
leaf_mask = LeafImage(:,:,2) > 32; %adjust the 32 if you want
inleaf_pixels = reshape( LeafImage(leaf_mask(:,:,[1 1 1])), [], 3);
leaf_mean = mean(inleaf_pixels, 1);
Now likewise you can find the mean colors for the two shades. With those in place, you can norm() the difference in mean colors (i.e., take the Euclidean distance)
  6 Commenti
Elvin
Elvin il 19 Dic 2013
1. By the way, may I ask what is the use of masking the leaf part in the image?
2. I see. Thanks for that. So, I need to use the leaf_mean(1,2) to get the mean of the G only.
3. So you're saying that I should use HSV instead of LAB or RGB?
Also, I'm now again confused with what color space to use. You're saying before that I should compare the mean color, so I should use the RGB, right? But in your last comment you said that nitrogen on the leaf is more of HSV. If you read Image Analyst's answer, he told me to use the LAB space. Which one should I use? RGB, HSV, or LAB?
By the way, I'm not after in measuring how much nitrogen is there on the leaf. I'm only after which of the following standard images is the test image closer in terms of the green color.
May I ask for code on what to do next after masking the leaf? You already gave me this code for masking the leaf, right?
LeafImage = imread('test1.jpg');
leaf_mask = LeafImage(:,:,2) > 32;
inleaf_pixels = reshape( LeafImage(leaf_mask(:,:,[1 1 1])), [], 3);
If I'm going to use the LAB space and use the Euclidean Distance, may I know what's the next code after the code above to convert the leaf only part into LAB, so I can get the L,A,B channels?
Thanks
Image Analyst
Image Analyst il 19 Dic 2013
You can probably find out which color it is closest to in any color space, but the more professional way that the pros use is LAB or HSV color space since it's more relevant to human vision than RGB space - in fact that's the whole reason why they were invented.

Accedi per commentare.


Ashish Dahal
Ashish Dahal il 24 Nov 2020
Hello Everyone,
I hope everybody is doing well. I want to know the color difference from shifting from YellowA to Yellow B to Yellow C. And same for the other colours from shifting from A to C. Or what is the relative change from going from YellowA to Yellow C?and same for other colours?
Best Regards
Ashish
  1 Commento
Image Analyst
Image Analyst il 24 Nov 2020
Modificato: Image Analyst il 24 Nov 2020
This is not an Answer. You should have started your own question. Anyway...
You can use delta E but first you have to get control over your image capture situation. Right now I can immediately see that it's a total mess.
First of all, the items are not even in the same location. Look how we're looking at the right side of the "A" objects but the left side of the "C" objects. They should all be centered in the field of view.
Secondly, you don't have control over your lighting. Just look how the background brightness varies. Presumably it's the same white background but it's not the same from snapshot to snapshot so how can we know if the color difference is due to illumination change, camera exposure change, or due to the object changing color?
Third, what about your camera? Are you using a flash? Hopefully not because flashes are not consistent in their light output. Are you using the camera in manual mode, or is it fully automatic? It should be in manual mode since you don't want the camera automatically changing anything or else you won't know if the color change is true to the object or just a side effect of the camera changing something.
Fourth, you need a color standard in there, like the X-rite Color Checker Chart. It should be in the field of view next to the disc. Then you can do a true calibration from RGB to CIELAB and that will help alleviate any of the exposure differences that might still remain. See attached tutorial for how to color calibrate a digital imaging system.
If you get control over those then you still should do a background correction to correct for the lens shading and illumination non-uniformities.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by