图像数据归一化
Matlab编程:
depth为源图像,数据分布在[0 63],归一化到[0 255]
ymin = 0;
ymax = 255;
depth = getnormaldata(depth, ymin, ymax)
function dst = getnormaldata(src, ymin, ymax)
src = double(src);
[m n] = size(src);
xmin = min(min(src));
xmax = max(max(src));
dst = (ymax-ymin)*(src-ones(m,n) * xmin)/(xmax-xmin) + ones(m,n)*ymin;
opencv编程:
normalize与convertTo
cv::Mat mat1=Mat(2,2,CV_32FC1);
mat1.at<float>(0,0) = 1.0f;
mat1.at<float>(0,1) = 2.0f;
mat1.at<float>(1,0) = 3.0f;
mat1.at<float>(1,1) = 4.0f;
// 对于这种小矩阵,还有更简单的赋值方式,找时间再改
cout<<"Mat 1:"<<endl;
cout<<mat1<<endl;
normalize(mat1,mat1,1.0,0.0,NORM_MINMAX);
cout<<"Mat 2:"<<endl;
cout<<mat1<<endl;
double costmax, costmin;
cv::minMaxIdx(ImgCost, &costmin,&costmax);
Mat cost(height, width, CV_8UC1);
//normalize(ImgCost, cost, 255,0,NORM_MINMAX);
ImgCost.convertTo(cost, CV_8U, 255/costmax);