Ask Your Question

Revision history [back]

How to use bilateralFilter function to operate CV_16UC1 data

I want to use bilateralFilter to operate a kinect depth image ,but the image is CV_16UC1 format that bilateralFilter function cant support.so I want to convert to CV_32FC1 to solve it.but It may not right after I do that.the following is my code.

enter code hereMat depth = imread("rgbd18.png", IMREAD_ANYDEPTH);
int cColorHeight = depth.rows;
int cColorWidth = depth.cols;
//双边滤波不支持CV_16UC1,所以转到CV_32FC1
Mat depth32f(cColorHeight, cColorWidth, CV_32FC1);
depth.convertTo(depth32f, CV_32FC1,1/65535.0);
Mat bilaterimg(cColorHeight, cColorWidth, CV_16UC1);
Mat bilaterimg32f(cColorHeight, cColorWidth, CV_32FC1);
// 原图,滤波输出的图,邻域的大小,灰度值权值公式中的方差,距离权值的方差
bilateralFilter(depth32f, bilaterimg32f, 5, 1, 1);
bilaterimg32f.convertTo(bilaterimg, CV_16UC1, 65535.0);
imwrite("bilater18.png", bilaterimg);