I need to do a histogram stretch

后端 未结 3 1599
迷失自我
迷失自我 2021-02-10 02:57

I have an array of BitmapFrames and need to do a histogram stretch. I know this is different from a histogram equalization, and what the final outcome is... sorta. the problem i

相关标签:
3条回答
  • 2021-02-10 03:43

    If you have control over the lighting and or gain/offset of the camera, you can optimize those and stretch the histogram as you desire.

    0 讨论(0)
  • 2021-02-10 03:44

    Don't forget to consider float. So a slight modification to dabonz413's answer:

    maxVal = image.maximumValue() # 153
    minVal = image.minumumValue() # 84
    dynamic = maxVal-minVal
    for pixel in image.Pixels():
        newPixel = ((float) (pixel-minVal)/dynamic)*255
    
    0 讨论(0)
  • 2021-02-10 03:48

    Histogram stretching is the mapping of pixel values such that:

    • the lowest value (e.g. 84 in the illustration) becomes 0
    • the highest value (e.g. 153 in the illustration) becomes 255 (in 8bit images)
    • and all the intermediate values are interpolated between that range (see illustration).

    In other words histogram stretching means stretching the dynamic of the image data (84:153) to the greatest possible dynamic (0:255).

    This should not affect the hight of the histogram peaks, but only their spread (the illustration is a bit misleading on this point).

    histogram stretch http://cct.rncan.gc.ca/resource/tutor/fundam/images/linstre.gif

    Image source

    In practice this is the mapping you would apply to the pixels of the image (pseudocode):

    maxVal = image.maximumValue() # 153
    minVal = image.minumumValue() # 84
    dynamic = maxVal-minVal
    for pixel in image.Pixels():
        newPixel = ((pixel-minVal)/dynamic)*255
    
    0 讨论(0)
提交回复
热议问题