opencv和matlab的bicubic算法有什么区别

opencv和matlab的bicubic算法有什么区别

本文介绍了opencv和matlab的bicubic算法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用opencv时调整大小

  img = cv2.imread('fname.png',0)
res = cv2.resize(img,None,fx = 2,fy = 2,interpolation = cv2.INTER_CUBIC)
cv2.imwrite('scaled_cv2.png',res)

和matlab的imresize

  I = imread(' fname.png'); 
J = imresize(I,2,'Antialiasing',false,'Method','bicubic');
imwrite(J,'scaled_matlab.png')

并与imagemagick的比较与

  compare -metric PSNR fname.png scaled_cv2.png diff_cv2.png 
compare -metric PSNR fname.png scaled_matlab.png diff_matlab.png

我得到完全不同的PSNR值
他们有什么不同?

解决方案

来自和OpenCV超调,但边缘更清晰,更好与真实底层高分辨率图像进行比较。


When using opencv's resize

img = cv2.imread('fname.png', 0 )
res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC)
cv2.imwrite('scaled_cv2.png',res)

and matlab's imresize

I = imread('fname.png');
J = imresize(I,2, 'Antialiasing', false, 'Method', 'bicubic');
imwrite(J,'scaled_matlab.png')

and comparing with imagemagick's compare with

compare -metric PSNR fname.png scaled_cv2.png diff_cv2.png
compare -metric PSNR fname.png scaled_matlab.png diff_matlab.png

I get completely different PSNR valuesWhat are they doing different?

解决方案

From Matlab's doc:

And from OpenCV's doc:

So the only explanation for this is that they use different weighting strategy to get the average value.

From Matlab imresize.m source, you can find that the kernel constant A (see Bicubic interpolation on Wikipedia) is set to -0.5, whereas it is set to -0.75 in OpenCV (see imgproc/src/imgwarp.cpp, function interpolateCubic() on github for instance).

This gives different kernel shapes for the convolution :

Therefore, you will end with slightly different results in the final interpolated image; typically more ringing artifacts and overshoot for OpenCV, but also sharper edges and a better PSNR compared with the "true" underlying high-resolution image.

这篇关于opencv和matlab的bicubic算法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:47