imresize - 试图理解双三次插值 [英] imresize - trying to understand the bicubic interpolation

查看:528
本文介绍了imresize - 试图理解双三次插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解这个功能:

  function [weights,indices] = contrib(in_length,out_length ,. .. 
scale,kernel,...
kernel_width,antialiasing)


if(scale< 1)&& (抗锯齿)
%使用修改后的内核同时插值和
%antialias。
h = @(x)scale * kernel(scale * x);
kernel_width = kernel_width / scale;
else
%无抗锯齿;使用未修改的内核。
h =内核;
结束

我真的不明白这条线是什么意思

  h = @(x)scale * kernel(scale * x); 

我的规模是0.5

内核是立方体。



但除此之外是什么意思?
我认为这就像创建一个稍后会调用的函数一样?

解决方案

imresize 在缩小图像时通过简单地扩展立方内核而不是离散的预处理步骤来完成抗锯齿。



对于 kernel_width 4像素(重新缩放后为8),其中贡献函数为每个像素使用10个邻居,内核 vs h (缩放内核)看起来像(非标准化,忽略x轴):





这比在单独的预处理步骤中首次执行低通滤波器或高斯卷积更容易。



立方内核定义在<$的底部c $ c> imresize.m as:

  function f = cubic(x)
%见键,数字图像的立方卷积插值
%Proc essing,IEEE声学,语音和信号交易
%Processing,Vol。 ASSP-29,第6号,1981年12月,p。 1155.

absx = abs(x);
absx2 = absx。^ 2;
absx3 = absx。^ 3;

f =(1.5 * absx3 - 2.5 * absx2 + 1)。*(absx< = 1)+ ...
(-0.5 * absx3 + 2.5 * absx2 - 4 * absx + 2)。* ...
((1< absx)&(absx< = 2));

,它将是连续的并具有连续的第一个导数。 OpenCV似乎使用-0.75



但是,如果你编辑[OPENCV_SRC] \modules\imgproc\src\imgwarp.cpp并更改代码:

  static inline void interpolateCubic(float x,float * coeffs)
{
const float A = -0.75f;
...

to:

  static inline void interpolateCubic(float x,float * coeffs)
{
const float A = -0.50f;
...

并重建OpenCV(提示:禁用CUDA和简称gpu模块)编译时间),然后你得到相同的结果。请参阅OP的相关问题我的其他答案中的匹配输出。


I'm trying to understand the function:

function [weights, indices] = contributions(in_length, out_length, ...
                                            scale, kernel, ...
                                            kernel_width, antialiasing)


if (scale < 1) && (antialiasing)
    % Use a modified kernel to simultaneously interpolate and
    % antialias.
    h = @(x) scale * kernel(scale * x);
    kernel_width = kernel_width / scale;
else
    % No antialiasing; use unmodified kernel.
    h = kernel;
end

I don't really understand what does this line means

 h = @(x) scale * kernel(scale * x);

my scale is 0.5
kernel is cubic.

But other than that what does it mean? I think it is like creating a function which will be called later ?

解决方案

imresize accomplishes anti-aliasing when downsizing an image by simply broadening the cubic kernel, rather than a discrete pre-processing step.

For a kernel_width of 4 pixels (8 after re-scaled), where the contributions function utilizes 10 neighbors for each pixel, the kernel vs h (scaled kernel) look like (unnormalized, ignore x-axis):

This is easier than first performing a low-pass filter or Gaussian convolution in a separate pre-processing step.

The cubic kernel is defined at the bottom of imresize.m as:

function f = cubic(x)
% See Keys, "Cubic Convolution Interpolation for Digital Image
% Processing," IEEE Transactions on Acoustics, Speech, and Signal
% Processing, Vol. ASSP-29, No. 6, December 1981, p. 1155.

absx = abs(x);
absx2 = absx.^2;
absx3 = absx.^3;

f = (1.5*absx3 - 2.5*absx2 + 1) .* (absx <= 1) + ...
                (-0.5*absx3 + 2.5*absx2 - 4*absx + 2) .* ...
                ((1 < absx) & (absx <= 2));

PDF of the referenced paper.

The relevant part is equation (15):

This is a specific version of the general interpolation equations for a = -0.5 in the following equations:

a is usually set to -0.5, or -0.75. Note that a = -0.5 corresponds to the Cubic Hermite spline, which will be continuous and have a continuous first derivitive. OpenCV seems to use -0.75.

However, if you edit [OPENCV_SRC]\modules\imgproc\src\imgwarp.cpp and change the code :

static inline void interpolateCubic( float x, float* coeffs )
{
    const float A = -0.75f;
    ...

to:

static inline void interpolateCubic( float x, float* coeffs )
{
    const float A = -0.50f;
    ...

and rebuild OpenCV (tip: disable CUDA and the gpu module for short compile time), then you get the same results. See the matching output in my other answer to a related question by the OP.

这篇关于imresize - 试图理解双三次插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆