# 为何 MATLAB imresize 函数和 OpenCV resize 函数结果不同

``````x = imresize([1,2;3,4],[4,4],'bilinear')
% x =
%     1.0000    1.2500    1.7500    2.0000
%     1.5000    1.7500    2.2500    2.5000
%     2.5000    2.7500    3.2500    3.5000
%     3.0000    3.2500    3.7500    4.0000
``````
``````    double data[] = {1, 2, 3, 4};
cv::Mat A(2, 2, CV_64FC1, data);
std::cout<<"Before: A = "<<A<<std::endl;
cv::resize(A, A, cv::Size(4, 4), cv::INTER_LINEAR);
std::cout<<"resize bigger: A = "<<A<<std::endl;
//    [1, 1.25, 1.75, 2;
//    1.5, 1.75, 2.25, 2.5;
//    2.5, 2.75, 3.25, 3.5;
//    3, 3.25, 3.75, 4]
``````

``````imresize(x,[2,2],'bilinear')
% ans =
%    1.5625    2.1875
%    2.8125    3.4375
``````
``````    cv::resize(A, A, cv::Size(2, 2), cv::INTER_LINEAR);
std::cout<<"resize smaller: A = "<<A<<std::endl;
//    [1.375, 2.125;
//    2.875, 3.625]
``````

``````imresize(x,[2,2],'bilinear','AntiAliasing',false)
% ans =
%    1.3750    2.1250
%    2.8750    3.6250
``````

``````#include <opencv2/opencv.hpp>
#include <iostream>

void demo_resize()
{
double data[] = {1, 2, 3, 4};
cv::Mat A(2, 2, CV_64FC1, data);
std::cout<<"Before: A = "<<A<<std::endl;
cv::resize(A, A, cv::Size(4, 4), cv::INTER_LINEAR);
std::cout<<"resize bigger: A = "<<A<<std::endl;
cv::resize(A, A, cv::Size(2, 2), cv::INTER_LINEAR);
std::cout<<"resize smaller: A = "<<A<<std::endl;
}
``````

原文作者：YimianDai
原文地址: https://www.jianshu.com/p/f3572eea6cf5
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。