本文介绍了如何规范化图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一系列像素,范围从-500到+1000,我如何规范化同一渐变上的所有像素,使它们落在特定范围之间,比如0到255?

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 and 255?

推荐答案

像这样的伪代码会将值从一个范围线性扩展到另一个范围

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
}

这篇关于如何规范化图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:51