# Contrast stretching Equation problem

How to determine $a$ and $b$ in this equation. I know how to determine $c$ and $d$ by looking at the intensity histogram. But what about $a$ and $b$?

$$P_{out}=(P_m -c)\left( \dfrac{b-a}{d-c} \right)+a$$

I think this is the equation you are using http://en.wikipedia.org/wiki/Normalization_%28image_processing%29

where b=newMin and a=newMax These values can also be found from your histogram. Usually you expand the new image to take up the full intensity range. The intensity range of your image is the X-axis of your histogram. If it goes from 0 to 1, then a=1, b=0 if your hsitogram is from 0 to 255 a=255,b=0

a=newMax= most likely the last value of the x-axis on your histogram
b=newMin= most likely the very first value of the x-axis on your histogram
c=Min=last  nonzero element in histogram
d=Max=first nonzero element in histogram

• Yes I understand it. But when I do not expand the new image to the full intensity range (i.e. 10-250) what is the logic there to decide that range? What I am asking is how to decide that newMax, newMin values? Is it just my preference to decide any range? – Samitha Chathuranga Mar 4 '15 at 4:05
• Well if you want to stretch the range from 10-250 your a=250 and b=10. Like the equation says the a=newMax is the new maximum value a pixel can take. Does that make sense? – andrew Mar 4 '15 at 5:12
• I should also add, this equation doesn't have to be used only for stretching. You can also use it for shrinking contrast. Say your current image uses the whole range 1-255 but for some reason you only want it to use 100-150. Just use 150 as newMax and 100 as newMin and you can shrink the contrast – andrew Mar 5 '15 at 17:48

Assume we want the output image still in the range of an image, i.e. an integer in [0, 255]. If you know $c$ and $d$, then $a$ and $b$ can be determined by solving equations below. $$( \min\{P_{in}\} - c ){( b - a )\over(d-c)}+a = 0\\ ( \max\{P_{in}\} - c ){( b - a )\over(d-c)}+a = 255$$

• Is the min{Pin} the minimum Gray value of the image? That is most probably 0 as most of the gray images have at least one white pixel – Samitha Chathuranga Mar 1 '15 at 14:20
• It depends on your image, normally a white pixel means ( 255, 255, 255 ), while black pixel means ( 0, 0, 0 ). You'd better find these numerical values for a given image. – pitfall Mar 1 '15 at 20:48
• Anyway so how to decide that range(in your example it is 0-255) of output image to be? Is there any logic there? – Samitha Chathuranga Mar 2 '15 at 2:49