大重九背后的故事
2021-03-05 11:27
采纳率: 66.7%
浏览 48

C++,OpenCV矩阵计算

代码中的tem = 255 * (tem - Min) / (Max - Min);

如何理解。

代码如下:

 

ReadLongWMat.create(512, 640, CV_16UC1);
LongW_FANMat.create(512, 640, CV_16UC1);

cv::flip(ReadLongWMat, LongW_FANMat, 0);
unsigned short* pData = (unsigned short*)(LongW_FANMat.data);

short tem = 0, Max = 0, Min = 32767;

for (int i = 0; i < 640; i++)
{
	for (int j = 0; j < 512; j++)
	{
		tem = ((*(pData + (j * 640 + i))));
		if (Max < tem)	Max = tem;
		if (Min > tem)	Min = tem;
	}
}

if (Max - Min <= 0)
{
	Min--; Max++;
}
for (int i = 0; i < 640; i++)
{
	for (int j = 0; j < 512; j++)
	{
		tem = ((*(pData + (j * 640 + i))));
		tem = 255 * (tem - Min) / (Max - Min); //什么原理
		if (tem > 255)	tem = 255;
		else if (tem < 0)	tem = 0;
		ShowLongWMat.data[j * 640 + i] = tem;
	}
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 爱晚乏客游 2021-03-05 14:12
    已采纳

    应该是将tem的值归一化到0-255之间,变成灰度图

    点赞 1 打赏 评论

相关推荐 更多相似问题