开发者

Having numbers generated in for loop how to output them as if their highest value was 1 and lowest 0?

开发者 https://www.devze.com 2023-02-09 06:12 出处:网络
So I have a black and white image in OpenCV, currently I output each of its per pixel color values into file so I get a file of values from 1 to 255. I have lots of really small images so in one image

So I have a black and white image in OpenCV, currently I output each of its per pixel color values into file so I get a file of values from 1 to 255. I have lots of really small images so in one image I usually get values that have small difference. like from 25 to 100.. So I need a way to print into file not color values but values from 0 to 1 where lowest color would be 0 and highest 1...

for(x=0;x<w;x++){
     for(y=0;y<h;y++){
          double RealColor = cvGetRe开发者_如何学编程al2D(source, y, x);
          file << RealColor << " ";
     }
     file << endl;
}file << endl;

How to do such a thing?


Just do a first pass, and find minimum and maximum values. Then do a second pass, and modify each value as (v - min) / (max - min) before writing to file.


This is better (OpenCV just have function to normalize between 0 and 1):

cvNormalize(source,source,1,0,CV_MINMAX );
0

精彩评论

暂无评论...
验证码 换一张
取 消