在for循环中生成的数字如何输出它们,就像它们的最高值是1和最低0一样?
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...
所以我在OpenCV中有一个黑白图像,目前我将每个像素颜色值输出到文件中,所以我得到一个从1到255的值的文件。我有很多非常小的图像所以在一个图像中我通常得到值差别很小。喜欢从25到100 ..所以我需要一种方法来打印到文件而不是颜色值,但值从0到1,其中最低颜色将是0和最高1 ...
for(x=0;x<w;x++){
for(y=0;y<h;y++){
double RealColor = cvGetReal2D(source, y, x);
file << RealColor << " ";
}
file << endl;
}file << endl;
How to do such a thing?
怎么做这样的事情?
2 个解决方案
#1
4
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.
只做第一遍,找到最小值和最大值。然后执行第二遍,并在写入文件之前将每个值修改为(v - min)/(max - min)。
更多相关文章
- 视差滚动与图像仅通过徽标透明度
- 如何使用Angular.js从json文件中使用id获取特定数据
- 如何从一个节点生成exe文件。js应用?
- 在批处理文件中使用JSMin
- 使用HTML文件中的React调用.js文件中的Javascript函数
- 在JavaScript中进行文件处理,第四部分:对象URLs
- [转]在网页中加入声音文件,并且用JavaScript对其进行播放控制
- 具有固定宽度网格的引导程序和应跨越窗口宽度的图像
- 基于缓冲区数据创建文件