mxy*_*mxy 9 matlab opencv numpy image-processing image-resizing
我正在将MATLAB代码传输到python并尝试使用OpenCV函数缩小图像cv2.resize,但是我得到了与MATLAB输出不同的结果.
为了确保我的代码在调整大小之前没有做错,我在两个函数上都使用了一个小例子并比较了输出.
我首先在Python和MATLAB中创建了以下数组并对其进行了上采样:
x = cv2.resize(np.array([[1.,2],[3,4]]),(4,4), interpolation=cv2.INTER_LINEAR)
print x
[[ 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. ]]
Run Code Online (Sandbox Code Playgroud)
x = imresize([1,2;3,4],[4,4],'bilinear')
ans =
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
Run Code Online (Sandbox Code Playgroud)
然后我拿出答案并将它们调整回原来的2x2大小.
cv2.resize(x,(2,2), interpolation=cv2.INTER_LINEAR)
ans =
[[ 1.375, 2.125],
[ 2.875, 3.625]]
Run Code Online (Sandbox Code Playgroud)
imresize(x,[2,2],'bilinear')
ans =
1.5625 2.1875
2.8125 3.4375
Run Code Online (Sandbox Code Playgroud)
它们显然不一样,当数字越大时,答案就越不同.
任何解释或资源将不胜感激.
cha*_*pjc 11
>> imresize(x,[2,2],'bilinear')
ans =
1.5625 2.1875
2.8125 3.4375
>> imresize(x,[2,2],'bilinear','AntiAliasing',false)
ans =
1.3750 2.1250
2.8750 3.6250
Run Code Online (Sandbox Code Playgroud)
这让我在过去绊倒了,同时试图重现imresize使用的结果interp2.