How do I normalize an image?

前端 未结 5 1885
轻奢々
轻奢々 2020-12-31 14:18

If I have a series of pixels, which range from say -500 to +1000, how would I normalize all the pixels on the same gradient so that they fall between a specific range, say 0

5条回答
  •  臣服心动
    2020-12-31 14:52

    Some pseudo code may help:

    foreach( pixel_value in pixel_values): # between -500 and 1000
    
        position = (pixel_value + 500) / 1500 # gives you a 0 to 1 decimal
        new_value = int(postion * 255) # or instead of casting, you could round it off
    

    That's python code by the way.

提交回复
热议问题