opencv的resize和matlab的imresize函数的计算在⽤c++代码复现matlab代码时,遇到两者resize函数的结果不相同的问题。
opencv:
resize(image1, reTmp, Size(50, 50), 0, 0, cv::INTER_LINEAR);
matlab:
tmp=imresize(img,[5050],'bilinear','AntiAliasing',false);
以⼀张500×396的彩⾊图⽚为例,resize到(50,50):
matlab  imresize代码:
img=imread('image/cluo.jpg');
img=single(img);
for i=1:10
fprintf('%.6f ',img(1,i,1));
end
fprintf('\n');
tmp=imresize(img,[5050],'bilinear','AntiAliasing',false);
for i=1:10
fprintf('%.6f ',tmp(1,i,1));
end
c++ resize代码:
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void main()
{
Mat image = imread("cluo.jpg");
printf输出格式matlab
Mat ws, ls, CV_32FC3);
for (int i = 0; i < ws; i++)
for (int j = 0; j < ls; j++)
{
image1.at<Vec3f>(i, j)[2] = image.at<Vec3b>(i, j)[0];
image1.at<Vec3f>(i, j)[1] = image.at<Vec3b>(i, j)[1];
image1.at<Vec3f>(i, j)[0] = image.at<Vec3b>(i, j)[2];
}
/
/打印输出resize前r通道前10个像素点的坐标
for (int i = 0; i < 10; i++)
printf("%.6f ", image1.at<Vec3f>(0, i)[0]);
printf("\n");
Mat reTmp;
resize(image1, reTmp, Size(50, 50), 0, 0, cv::INTER_LINEAR);
//resize(image1, reTmp, Size(50, 50), 0, 0, cv::INTER_NEAREST);
//打印输出resize后r通道前10个像素点的坐标
for (int i = 0; i < 10; i++)
printf("%f ", reTmp.at<Vec3f>(0, i)[0]);
printf("\n");
system("pause");
}
结果⽐较:
结果基本相同
matlab中默认的    tmp=imresize(img,[50 50],'bilinear');    函数是打开了抗锯齿结果和opencv中的INTER_LINEAR不相同
matlab  和  opencv中  nearest  ⽅式的结果⽐较:
c++:    resize(image1, reTmp, Size(50, 50), 0, 0, cv::INTER_NEAREST);
matlab:  tmp=imresize(img,[50 50],'nearest');
matlab:  tmp=imresize(img,[50 50],'nearest','AntiAliasing',false);结果不相同

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。