Find contrast ratio of a picture?
Find contrast ratio of a picture?
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
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
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?
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
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?
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:
What does the value between parentheses mean?
Thanks
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)
Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
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:
What does the value between parentheses mean?Code: Select all
mean: 104.649 (0.41039) standard deviation: 105.973 (0.415581)
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?
Interesting. So what would be the formula for getting the value between 0-1 with the "normal" standard deviation value?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
see http://en.wikipedia.org/wiki/Standard_d ... properties where x is the image value in the range 0 to 1.novito wrote:Interesting. So what would be the formula for getting the value between 0-1 with the "normal" standard deviation value?
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?
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
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
Last edited by novito on 2013-12-02T18:25:13-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
There are 4 images on each link. Which ones are you interested in?
Re: Find contrast ratio of a picture?
Sorry. I have edited the URLs. Now they should be just one image per URL
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
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?
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Find contrast ratio of a picture?
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)
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?
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.
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.