Hi
I have two images with difference in brightness. Now i want to set the brightness of first image to the second image.
How to get the "contrast"/average gray level of an entire image.
I am doing this in C++ by using Matick++. How can i get the gray level of an image in C++.
I am able to change the brightness of an entire image with contrast method of IM. Is there any method like this to get contrast value for an entire image.
If i try to get gamma i am getting 0.0. Why i am getting gamma value as ZERO.
Can you please tell me what is the main difference of "gamma" & "contrast"
ThanksInAdvance
How to get average gray level of an image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get average gray level of an image
The average graylevel of an image may be found using the string format "%[mean]"
convert image -format "%[mean]" info:
see http://www.imagemagick.org/script/escape.php
The average is a reasonable measure of brightness.
Another way to get the average is to just reduce the image to 1 pixel and get its color:
convert image -scale 1x1! -format "%[pixel:s.p{0,0}]" info:
Contrast is harder to measure. But a reasonable measure is just the standard deviation
convert image -format "%[standard-deviation]" info:
You can change the brightness of an image using -modulate in HSB mode.
see http://www.imagemagick.org/Usage/color/#modulate
I have a script called bcimage that allows you to change the brightness, contrast and/or saturation of an image by percent change. So if you measure the mean and std of the two image, you can calculate the percent change and feed those to bcimage.
Also, if you know how you created the first image, you can use the new -hald-clut to apply the same changes to all other images.
see
http://www.imagemagick.org/script/comma ... #hald-clut
http://www.imagemagick.org/Usage/color/#hald-clut
convert image -format "%[mean]" info:
see http://www.imagemagick.org/script/escape.php
The average is a reasonable measure of brightness.
Another way to get the average is to just reduce the image to 1 pixel and get its color:
convert image -scale 1x1! -format "%[pixel:s.p{0,0}]" info:
Contrast is harder to measure. But a reasonable measure is just the standard deviation
convert image -format "%[standard-deviation]" info:
You can change the brightness of an image using -modulate in HSB mode.
see http://www.imagemagick.org/Usage/color/#modulate
I have a script called bcimage that allows you to change the brightness, contrast and/or saturation of an image by percent change. So if you measure the mean and std of the two image, you can calculate the percent change and feed those to bcimage.
Also, if you know how you created the first image, you can use the new -hald-clut to apply the same changes to all other images.
see
http://www.imagemagick.org/script/comma ... #hald-clut
http://www.imagemagick.org/Usage/color/#hald-clut
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: How to get average gray level of an image
Their is a number of ways to change an image so that its average brightness matches, or even its average color matches that of an other image. add the difference, multiply (modulate), gamma adjust, etc...
If you play with this let us know what you find out.
I do know that brightness matching and blending is often needed as part of pamorama image processing, so it may give you some help.
Rick Mabry also have done image average modification work.. His notes are located at
http://www.lsus.edu/sc/math/rmabry/imagemagick/avgdemo/
If you play with this let us know what you find out.
I do know that brightness matching and blending is often needed as part of pamorama image processing, so it may give you some help.
Rick Mabry also have done image average modification work.. His notes are located at
http://www.lsus.edu/sc/math/rmabry/imagemagick/avgdemo/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get average gray level of an image
For what it is worth (and I do not expect too much) I have uploaded a new script to my site, bcmatch, that attempts to match the brightness and contrast of one image to that of another. It is limited as it only uses b/c which are linear effects. Thus it cannot handle such non-linear modifications as gamma. Also once information is lost in an image (perhaps due to being too high contrast), it cannot generally be recovered. Thus this technique, seems to work better on dark, low contrast image than bright high contrast images. But I have only tested with a couple of examples.
I have also uploaded another new script to my site, histmatch, that attempts to match the histogram of one image to that of another. It uses a non-linear transformation. But again, once information is lost in an image (perhaps due to being too high contrast), it cannot generally be recovered.
I have also uploaded another new script to my site, histmatch, that attempts to match the histogram of one image to that of another. It uses a non-linear transformation. But again, once information is lost in an image (perhaps due to being too high contrast), it cannot generally be recovered.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get average gray level of an image
Please note that my histmatch script has a problem and currently only works correctly for two images the same size. I am working to correct that and will report back later when done.
_____________________
OK. I believe I have it fixed now.
_____________________
OK. I believe I have it fixed now.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How to get average gray level of an image
With Anthony's help and some study of awk (and changing while loops to for loops), I have been able to make a 10x speed improvement (on a 128x128 image) in redist and histmatch.