Please register to participate in our discussions with 2 million other members - it's free and quick! Some forums can only be seen by registered members. After you create your account, you'll be able to customize options and access all our 15,000 new posts/day with fewer ads.
Hi,
I want to make an image darker - allocating the top brightest 25% of grey values over the full range (0-255). This is because parts of the image are washed out, and very bright and I suspect there is more information there if I could extend the range of greys.
However, my brain just refuses to function for me so I was wondering if some math-minded person could help me please.
The 8-bit image grey values range from 30-229, so the brightest pixel in the image is 229 and the darkest is 30.
I would like to allocate the range from 172 to 229 to be 0 to 255 so that would be stretching a range of brighter pixels to have a slightly larger top and greater bottom value.
I have done it for the darker end of the image but my mind will not wrap around making the bright areas darker.
For anyone who wants to do this stretching from darker to lighter, the formula I have been using which seems to work well is
(np is numpy)
pixel_in = img[down,left]
a = 0 # min value output range
b = 255 # max value output range
c = np.min(img) # lower limit of pixel value (30)
d = np.max(img) # upper limit of pixel value (229)
ba = b - a
dc = d - c
badc = float(ba/dc)
pixel_out = int( (pixel_in - c) * badc ) + a