Page 1 of 1

Get Brightness value from key image.....

Posted: 2009-06-24T05:26:47-07:00
by asha09
Hi All................
Im developing a small vc++ application......In this application im loading list of images...
My task is... Get Brightness,Contrast and Gamm values from one key image and set those values to remaining all frames....
im using Visual studio 6.0 and ImageMagick-6.3.4...
Please help me......How can i do this....


ThanksInAdvance.....

Re: Get Brightness value from key image.....

Posted: 2009-06-24T08:08:23-07:00
by fmw42
see comments on recent topic at viewtopic.php?f=1&t=14073

gamma is hard to measure

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

Re: Get Brightness value from key image.....

Posted: 2009-06-24T21:39:10-07:00
by asha09
Am not creating first image....just am loading sequence of gray scale images....in that am i selecting one key frame....
And finding brightness value, Contrast value and Gamma value of that image....
here is the problem how can i get these values.......

How can i get ( means how can i start) that script language in my pc.....please explain about that script language....

Thanks......

Re: Get Brightness value from key image.....

Posted: 2009-06-24T23:12:57-07:00
by fmw42
Sorry but I don't know of any way to measure the gamma of an image. If anyone knows of such a technique, I would certainly like to hear about it.

The definitions of brightness and contrast of an image are also somewhat arbitrary. Typically the overall brightness of an image is associated closely with the average (or mean) graylevel value accumulated from all the channels. Contrast is harder to define, but statistically, it is often associated loosely with the standard deviation of the graylevels values accumulated from all the channels. Both of these can be extracted from an image using IM identify -verbose imagename. Or through the use of string formats. See http://www.imagemagick.org/script/escape.php.

Typically one uses the terms of brightness and contrast to indicate a linear transformation between two images or how one adjusts or changes the brightness and contrast of an image. In other words, in a linear transformation of graylevels, the contrast change is the slope of the transformation (line) and the brightness change is the intercept. Gamma represents a non-linear change of the image graylevels and is represented by an exponential curve rather than a straight line.

From a simple statistical perspective, one can change the brightness and contrast of an image to match that of another image by changing the slope and intercept of a linear transformation. In such case, the contrast change=(s1-s2)/s1 and the brightness change=(m1-m2)/m1 where m1 and m2 are the mean (average) values of the two images and s1 and s2 are the standard deviations of the two images. The slope of the line is then 1+(s1-s2)/s1 and intercept can be computed from the brightness change and the slope, but is somewhat more complicated.

In IM you can then use -function polynomial "$a,$b" where a=slope and b=intercept to modify the one image to try to match those statistics of the other image. I am working on a script to do this. However, it is important to note that 1) once information is lost due to being too bright or too contrasty, it is impossible to get it back and 2) this linear approximation is not terribly good. Images are not so simple. Point being that changes between two versions of a given image are not necessarily linear as one can apply non-linear transformations such as gamma to an image.

Consequently, a better approach is to force one image's histogram to match that of another. This accounts for non-linear effects. This is possible with an approach similar to what I use in my redist script to change the histogram of an image to force it to match a gaussian shape. In a similar manner one could force an images histogram to match that of any other image. I have not yet made such a script, but it is on my list of things to work on. However, it will not be very fast, because it is a script and does a lot of calculations in the shell. Furthermore, again I have to emphasize even with such histogram modification one cannot recover information that has already been lost.

Re: Get Brightness value from key image.....

Posted: 2009-06-25T01:22:30-07:00
by asha09
thanks for ur help....
Im developing vc++ application.....I want algorithm or list of functions for finding the Brightness value and Contrast value of image...
please i want code in vc++ only, not in scripting command line format....

Anybody help me...

Is there any procedure or function to find Brightness value of image....?

Re: Get Brightness value from key image.....

Posted: 2009-06-25T02:23:52-07:00
by asha09
The following logic is only for finding Brihtness of pixel .....like that i want Brightness of image...

one easy way to find the 'brightness' of a pixel is just take the red green and blue components and stick them in this formula:



brightness = 0.299 * R + 0.587 * G + 0.114 * B



This is similar to your averaging approach, but the green contributes more due to the way our eyes work.



Another easy way is to find the minimum of red, green, blue, and the maximum of the red, green, blue, and average those. For example, if you had a color (.2, .3, .8), the minimum is .2 and the maximum is .8, so the brightness would be (.2 + .8)/2 = .5.

Re: Get Brightness value from key image.....

Posted: 2009-06-25T08:35:38-07:00
by fmw42
convert your image to the colorspace you want that matches your formula for brightness and get the average color from the string formats. The string formats get the average for the whole image or channel.

convert image -colorspace XXX -format "%[mean]" info:

see
http://www.imagemagick.org/script/comma ... colorspace

You can also get the intensity or luminance combinations for the image from fx escapes after averaging the image down to one pixel per channel

see intensity and luminance formula at
http://www.imagemagick.org/script/comma ... colorspace

convert image -scale 1x1! -format "%[fx:luminance]" info:


Alternately scale the image to one pixel to get its average per channel, then combine the channels with any formula you want to mix the red, green, blue

R=`convert image -scale 1x1! -format "%[fx:mean.r]" info:`
G=`convert image -scale 1x1! -format "%[fx:mean.g]" info:`
B=`convert image -scale 1x1! -format "%[fx:mean.b]" info:`

brightness=`convert xc: -format "%[ 0.299 * $R + 0.587 * $G + 0.114 * $B]" info:`

Sorry I cannot tell you how to do this any API.

Re: Get Brightness value from key image.....

Posted: 2009-06-25T15:06:49-07:00
by fmw42
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.

Re: Get Brightness value from key image.....

Posted: 2009-06-30T20:21:38-07:00
by fmw42
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.

Re: Get Brightness value from key image.....

Posted: 2009-07-01T01:23:39-07:00
by asha09
hi.........

i want code in VC++.....only.....In my application im not using any script...So please help in VC++....How can i get image Brightness Value and How can i apply this Brightness value to my Color image.....

The following code Set Brightness value to Gray scale image.....

for( i=0;i<m_CurrentImg.GetHeight();i++)
{
for(int j=0;j<m_CurrentImg.GetWidth();j++)
{
idx=((j)*columns)+(i);

long R=Pixel[idx].red; //Bright Started
long G=Pixel[idx].green;
long B=Pixel[idx].blue;

R=R/255;
G=G/255;
B=B/255;

R=R+m_Brightness;
G=G+m_Brightness;
B=B+m_Brightness;

if(R<0) R=0; if(R>255) R=255;
if(G<0) G=0; if(G>255) G=255;
if(B<0) B=0; if(B>255) B=255;

Pixel[idx].red=R*255;
Pixel[idx].green=G*255;
Pixel[idx].blue=B*255;//Bright Ended
}


But i want Same code for color images....


ThanksInAdvance...

Re: Get Brightness value from key image.....

Posted: 2009-07-01T10:45:08-07:00
by fmw42
sorry i know nothing about VC++

Re: Get Brightness value from key image.....

Posted: 2009-07-01T21:27:22-07:00
by asha09
Its k....thanks............