Image comparison - grayscale issue
Image comparison - grayscale issue
I'm using IM for automating my application. For that I used image comparison to check whether certain Menu items are highlighted or not.
Used NCC metric in grayscale mode for comparison. Some times the images rendered will have brightness issue i.e. due to the rendering h/w. So used NCC in grayscale mode which address this brightness issue gracefully. After experimenting observed a 90%+ accuracy level for NCC grayscale compariosn for match cases.
input img1 :
input img2:
Here img1 is the highlighted menu item compared against with the current image - ie. img2. Here NCC in RGB colormode returns : 73% match.
grayscale img1:
grayscale img2:
In NCC grayscale colorspace returns 91.6% accuracy. So the image comparison is passed. Actually it is not an expected behaviour for my scenario. I need to signal pass only if the text is 'Setup' and it is highlighted with yellow.
Is this a limitation in grayscale mode for color comparison ?
Is their any other ways in ImageMagick to better solve this issue.
Thanks in advance
Used NCC metric in grayscale mode for comparison. Some times the images rendered will have brightness issue i.e. due to the rendering h/w. So used NCC in grayscale mode which address this brightness issue gracefully. After experimenting observed a 90%+ accuracy level for NCC grayscale compariosn for match cases.
input img1 :
input img2:
Here img1 is the highlighted menu item compared against with the current image - ie. img2. Here NCC in RGB colormode returns : 73% match.
grayscale img1:
grayscale img2:
In NCC grayscale colorspace returns 91.6% accuracy. So the image comparison is passed. Actually it is not an expected behaviour for my scenario. I need to signal pass only if the text is 'Setup' and it is highlighted with yellow.
Is this a limitation in grayscale mode for color comparison ?
Is their any other ways in ImageMagick to better solve this issue.
Thanks in advance
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image comparison - grayscale issue
For a fair comparison between your two grayscale images, you should negate one before the comparison. One image white on black and the other is black on white
Test for yellow before you convert to grayscale.
You can convert to two colors and get the two colors from -unique-colors. Then check that you have something close to your desired yellow and something close to black for the two colors.
Test for yellow before you convert to grayscale.
You can convert to two colors and get the two colors from -unique-colors. Then check that you have something close to your desired yellow and something close to black for the two colors.
Re: Image comparison - grayscale issue
Thanks Fred for the reply. Can you please explain little bit more on the below statement(with commands)
You can convert to two colors and get the two colors from -unique-colors. Then check that you have something close to your desired yellow and something close to black for the two colors.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image comparison - grayscale issue
Actually a better method is the following. Rather than getting unique colors, which does not work well as tested, just get the mean color of the image.
srgb(184,160,55)
or slightly better is to correct the mean for the black text
srgb(168,149,54)
So now use a test to compare the mean yellow from a reference that you know is good to the mean of any image. If the values are not close enough, no point with doing the grayscale compare.
21868.2 (0.333687)
Change the yellow color to your real good yellowish color standard.
Code: Select all
convert 2v0g83r.png -alpha off -depth 8 -scale 1x1 -format "%[pixel:u.p{0,0}]\n" info:
or slightly better is to correct the mean for the black text
Code: Select all
convert 2v0g83r.png \
\( -clone 0 -alpha off -depth 8 -fuzz 40% -fill black -opaque black -scale 1x1 \) \
\( -clone 0 -alpha off -depth 8 -fuzz 40% -fill black -opaque black -fill white +opaque black \) \
-delete 0 +swap -compose divide -composite -format "%[pixel:u.p{0,0}]\n" info:
So now use a test to compare the mean yellow from a reference that you know is good to the mean of any image. If the values are not close enough, no point with doing the grayscale compare.
Code: Select all
compare -metric rmse xc:yellow xc:"srgb(168,149,54)" null:
Change the yellow color to your real good yellowish color standard.
Re: Image comparison - grayscale issue
Thanks Fred for the inputs. I'm trying out the options, you have mentioned in my project.
Can you please clarify the command
Does that mean, it returns the (0,0) pixel value ?
Also scaling internally does the mean operation ?
Can you please clarify the command
Code: Select all
"%[pixel:u.p{0,0}]\n"
Does that mean, it returns the (0,0) pixel value ?
Also scaling internally does the mean operation ?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image comparison - grayscale issue
Code: Select all
"%[pixel:u.p{0,0}]\n"
see
http://www.imagemagick.org/Usage/transform/#fx_other
accessing pixels section near the bottom of http://www.imagemagick.org/script/fx.php
the scale computes the mean of each channel as a single pixel, but you need the above to extract the color values (unless you are using Q8). Alternately you could send the single pixel to txt: output, but that would then require further filtering to get the color.
Re: Image comparison - grayscale issue
OK Fred.
Currently I'm using ImageMagick-6.8.6-Q16 in Windows 7 platform. Also used Im4Java for interfacing Java to IM command line.
I couldn't find a way to directly query the image information. But http://im4java.sourceforge.net/docs/dev ... html#utils exposes a set of generic image properties. I couldn't find a way to get the pixel color from Info class.
But I tried the following commands in IM4Java
convert input1.png -alpha off -depth 8 -scale 1x1 input1-scaled.png
convert input2.png -alpha off -depth 8 -scale 1x1 input2-scaled.png
Later compared
compare -metric rmse input1-scaled.png input2-scaled.png null:
This gives exactly the same result as the one you have mentioned. Can you please confirm whether the approach is correct or not.
Code: Select all
the scale computes the mean of each channel as a single pixel, but you need the above to extract the color values (unless you are using Q8). Alternately you could send the single pixel to txt: output, but that would then require further filtering to get the color.
I couldn't find a way to directly query the
Code: Select all
-format "%[pixel:u.p{0,0}]\n" info:
But I tried the following commands in IM4Java
convert input1.png -alpha off -depth 8 -scale 1x1 input1-scaled.png
convert input2.png -alpha off -depth 8 -scale 1x1 input2-scaled.png
Later compared
compare -metric rmse input1-scaled.png input2-scaled.png null:
This gives exactly the same result as the one you have mentioned. Can you please confirm whether the approach is correct or not.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image comparison - grayscale issue
Yes that would also work to get the color of the yellow in the test image. But I thought you needed to compare that to some standard yellow color. If you do then
compare -metric rmse input1-scaled.png xc:"standardyellowcolor" null:
would work.
If you have a master image of the correct color, then
compare -metric rmse input1-scaled.png input2-scaled.png null:
where one of the scaled images comes from the test image and the other from the master image.
compare -metric rmse input1-scaled.png xc:"standardyellowcolor" null:
would work.
If you have a master image of the correct color, then
compare -metric rmse input1-scaled.png input2-scaled.png null:
where one of the scaled images comes from the test image and the other from the master image.
Re: Image comparison - grayscale issue
Yes Fred, I've the master image against which I am testing the current image.
Thanks for the confirmation.
Thanks for the confirmation.