Welcome to City-Data.com Forum!
U.S. CitiesCity-Data Forum Index
Go Back   City-Data Forum > General Forums > Science and Technology > Computers
 [Register]
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.
View detailed profile (Advanced) or search
site with Google Custom Search

Search Forums  (Advanced)
 
Old 09-09-2020, 05:12 AM
 
Location: PRC
6,945 posts, read 6,869,734 times
Reputation: 6525

Advertisements

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

Thanks for any help.
Reply With Quote Quick reply to this message

 
Old 09-10-2020, 06:05 AM
 
Location: PRC
6,945 posts, read 6,869,734 times
Reputation: 6525
OK, I figured something out. Thanks.
Reply With Quote Quick reply to this message
Reply
Please update this thread with any new information or opinions. This open thread is still read by thousands of people, so we encourage all additional points of view.

Quick Reply
Message:


Over $104,000 in prizes was already given out to active posters on our forum and additional giveaways are planned!

Go Back   City-Data Forum > General Forums > Science and Technology > Computers

All times are GMT -6.

© 2005-2024, Advameg, Inc. · Please obey Forum Rules · Terms of Use and Privacy Policy · Bug Bounty

City-Data.com - Contact Us - Archive 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 - Top