Page 1 of 1

Detect constant color channel using ImageMagick

Posted: 2013-10-09T11:23:55-07:00
by appu
Hi All,

I am using ImageMagick-6.8.6-Q16 for my image comparison activities in my project. I need to verify the whether my applications correctly renders the images by doing image comparisons.

Initially I used NCC approach in grayscale mode. But observed that it is not suited for constant color channel i.e. an image with a constant opaque color. In constant color case, the NCC accuracy is below 50%. So I checked the RMSE approach and it returns promising results. Similar colors have very low RMSE error.

Now I need to identify whether the current image to be tested is constant color channel(eg. img1) OR an image with some objects painted on it. (eg. img2)

Constant color img1 : Green.png http://i41.tinypic.com/206lfle.png
Images with objects img2: cartoon.png http://i43.tinypic.com/34ha06g.png


Please help me to resolve this issue.Thanks in Advance.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-09T11:51:53-07:00
by snibgo
I'm not sure what you are asking, but:

Code: Select all

convert in.png -format "%%[fx:minima.r] %%[fx:maxima.r] %%[fx:minima.g] %%[fx:maxima.g] %%[fx:minima.b] %%[fx:maxima.b]" info:-
(Windows script syntax. For Unix, don't double the "%".)

This spits out 6 numbers. For a constant colour, the first pair will be equal, as will the second pair, and the third. In a script, extract the numbers and compare.

You can probably write an expression that returns a simple 0 or 1.

There are other ways that might be quicker, such as making a copy the same size but completely the colour of one pixel from in.png, and comparing the two images.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-09T13:54:42-07:00
by fmw42
Just use the standard_deviation value. If zero, then it is a constant color.

convert in.png -format "%[fx:standard_deviation]" info:

That should get the overall std of all the channels.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-09T14:27:31-07:00
by snibgo
Ah, yes, of course, far better. Thanks.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-09T19:09:22-07:00
by appu
Thanks fmw42, snibgo for your suggestions. But when I tried your approach, I got the following results

convert highlight.png -format "%[fx:standard_deviation]" info:
0.0819818

convert highlight.png -format "%[fx:minima.r] %[fx:maxima.r] %[fx:minima.g] %[fx:maxima.g] %[fx:minima.b] %[fx:maxima.b]" info:-
0.784314 0.988235 0.698039 0.92549 0.254902 0.576471

So I understood that these are not pure constant color channels. They have a small gradient in them, which visually seems like a constant color channel. Can you please help me identify gradient cases also ?

sample image tested : Image

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-09T19:20:54-07:00
by fmw42
Note that those values are in the range 0 to 1. So rather small. But with a gradient, if the same hue, then you can convert to HSL and extract the hue channel and test the same way.

convert 2eg9zec.png -colorspace HSL -channel r -separate +channel -format "%[fx:standard_deviation]" info:
0.00363458

So this is a 0.36% difference from a pure hue.

Thus your gradient is not a perfect hue, but is very close.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-11T00:05:34-07:00
by appu
That worked. You are awesome Fred ! :)

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-23T05:23:25-07:00
by appu
Hi Fred,

I'm newbie to image processing stuffs. In the earlier reply, you have extracted channel r from the image to get the hue.

Code: Select all

convert 2eg9zec.png -colorspace HSL -channel r -separate +channel -format "%[fx:standard_deviation]" info:
Can you please explain why you extracted channel r and not channel b or channel g ?
If there are any reference links, please share it.

Thanks

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-23T09:48:40-07:00
by snibgo
When an image has 3 channels, they are referred to as "R", "G" and "B", even when they represent something else.

After converting the colorspace to HSL, the first channel represents Hue. The second represents Saturation, and the thirds represents Lightness.

Re: Detect constant color channel using ImageMagick

Posted: 2013-10-23T10:10:38-07:00
by appu
OK. Got it. Thanks Snibgo for the clarification.