Page 1 of 2
Find contrast ratio of a picture?
Posted: 2013-11-26T17:43:24-07:00
by novito
I am using Minimagick, a Ruby wrapper based on Mogrify.
I am interested on finding the contrast ratio of a picture. I want to use that information to score image depending on how likely they are to be a logo picture. I will have several pictures which have a low contrast (all the picture is the same color, or all the picture is the same color except a column...) and I will have one picture that will be a logo. I am assuming that if I get the contrast ratio, logos usually will have a high contrast ratio and therefore I will be able to discard the other pictures in favor of the logo.
Any thoughts on how can I get the contrast ratio using ImageMagick or Mogrify?
Re: Find contrast ratio of a picture?
Posted: 2013-11-26T18:26:07-07:00
by fmw42
Get the min and max values of a grayscale version of the image. If the difference is small, it is low contrast, if large it is high contrast.
Perhaps better is to get the standard deviation of the grayscale image. If that is large than high contrast, if small, then low contrast. All of these measure are in the -verbose info: or can be obtained from string formats. See
http://www.imagemagick.org/script/escape.php
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T09:53:35-07:00
by novito
Thanks for the reply. I have a question, when you say 'get max and min values' from grayscale, which values are you refering to? Also, when you talk about standard deviation, why would I want to do the standard deviation of a grayscaled image, and not just the colorful one?
Also, what about using the 'features' from Mogrify?
http://www.imagemagick.org/script/comma ... p#features. It is stated that we can take the contrast from there. However, I don't know what that argument 'distance' mean. Any help?
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T11:22:04-07:00
by fmw42
novito wrote:Thanks for the reply. I have a question, when you say 'get max and min values' from grayscale, which values are you refering to? Also, when you talk about standard deviation, why would I want to do the standard deviation of a grayscaled image, and not just the colorful one?
Also, what about using the 'features' from Mogrify?
http://www.imagemagick.org/script/comma ... p#features. It is stated that we can take the contrast from there. However, I don't know what that argument 'distance' mean. Any help?
You can get the overall and each channel statistics (min, max, mean, std, etc) from
identify -verbose yourimage
Using the grayscale value tells you one single number. If you want r,g,b standard deviations, that is up to you. But then you have to check 3 values.
The -features function only looks locally within a small distance of each pixel and accumulates the values over the whole image. I am not sure that is what you want.
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T11:41:26-07:00
by novito
Perfect! I think now I understand. Thanks, I will go for the grayscale.
I have just one last question. I see two values in the mean and standard deviation info:
Code: Select all
mean: 104.649 (0.41039)
standard deviation: 105.973 (0.415581)
What does the value between parentheses mean?
Thanks
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T11:51:12-07:00
by fmw42
novito wrote:Perfect! I think now I understand. Thanks, I will go for the grayscale.
I have just one last question. I see two values in the mean and standard deviation info:
Code: Select all
mean: 104.649 (0.41039)
standard deviation: 105.973 (0.415581)
What does the value between parentheses mean?
Thanks
The first one is the value in the range 0 to quantumrange, where quantumrange is 255 for Q8 compile or depth 8 and 65535 for Q16 compile or depth 16 images. The value in parenthesis is always in the range 0 to 1. So if multiplied by 100, it is percent of max value
The overall values are the accumulated values from all channel, so similar to grayscale.
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T14:26:59-07:00
by novito
Interesting. So what would be the formula for getting the value between 0-1 with the "normal" standard deviation value?
Re: Find contrast ratio of a picture?
Posted: 2013-11-27T16:19:50-07:00
by fmw42
novito wrote:Interesting. So what would be the formula for getting the value between 0-1 with the "normal" standard deviation value?
see
http://en.wikipedia.org/wiki/Standard_d ... properties where x is the image value in the range 0 to 1.
So it is the average of the square of all the pixel values minus the square of the average of all the pixel values.
The standard deviation measures how far the data spreads from the mean value. If the standard deviation is small there is less spread to the data and the image is low contrast. If the image spreads far from the mean, then it has higher contrast (for example if there are two peaks in the histogram (on on each side of the mean), then some data is dark and some is bright, thus higher contrast.
Re: Find contrast ratio of a picture?
Posted: 2013-12-02T17:53:54-07:00
by novito
Thanks for your help.
I am wondering why this image
http://s27.postimg.org/5c1vhgfhv/logo.png has a lower standard deviation than this one:
http://s15.postimg.org/3n57al9tj/image.png
It seems to me that the first one is likely to have higher contrast than the second one right?
I am asking this because the main approach for me to have the standard deviation is to find out what is likely to be a logo, and obviously the first one is.
Thanks
Re: Find contrast ratio of a picture?
Posted: 2013-12-02T18:14:31-07:00
by fmw42
There are 4 images on each link. Which ones are you interested in?
Re: Find contrast ratio of a picture?
Posted: 2013-12-02T18:25:34-07:00
by novito
Sorry. I have edited the URLs. Now they should be just one image per URL
Re: Find contrast ratio of a picture?
Posted: 2013-12-02T19:10:30-07:00
by fmw42
The second image has only black and white. The first image has shades of gray. So I suppose that is why the first is a lower std.
Re: Find contrast ratio of a picture?
Posted: 2013-12-09T15:54:37-07:00
by novito
I see...
This is interesting. So, what do you think I could do in order to find a measure that would let me differentiate between images that are purely backgrounds (such as this one:
http://www.skatewarehouse.com/img/grip-tile-header.jpg) and a picture that is a logo, such as this one:
http://postimg.org/image/eqd86p49v/
In this case I would expect the second one to give me a higher std, but nopes, the first one does.
Thanks a lot for your help. This is really helpful.
Re: Find contrast ratio of a picture?
Posted: 2013-12-09T16:31:32-07:00
by fmw42
The first image std is lower (at 0.02) and the second is higher (at 0.1). You are off a decimal place! The second image has 5x the std of the first.
First image (grayscale - only one channel gray):
standard deviation: 5.55881 (0.0217993)
(if it were uniformly the same gray, the std would be 0)
Second image (3 channels, using overall statistics):
standard deviation: 27.1062 (0.106299)
Re: Find contrast ratio of a picture?
Posted: 2013-12-09T16:37:12-07:00
by novito
Ouch.
I guess I am not guetting correctly the std then. I will digg further and come back if any doubts. I am parsing the output of mogrify so maybe I am getting the number wrong, but I was getting higher std for the first one
Thanks, I will take a second look.