How do I normalize an image?

前端 未结 5 1875
轻奢々
轻奢々 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:48

    Some pseudocode like this would scale values linearly from one range to another

    oldmin=-500
    oldmax=1000
    oldrange=oldmax-oldmin;
    
    newmin=0
    newmax=255;
    newrange=newmax-newmin;
    
    foreach(oldvalue)
    {
        //where in the old scale is this value (0...1)
        scale=(oldvalue-oldmin)/oldrange;
    
        //place this scale in the new range
        newvalue=(newrange*scale)+newmin
    }
    

提交回复
热议问题