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

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

问题描述

我正在尝试理解函数:

function [权重,指数] = 贡献(in_length, out_length, ...规模,内核,...kernel_width,抗锯齿)if (scale <1) &&(抗锯齿)% 使用修改后的内核同时插入和% 抗锯齿.h = @(x) scale * kernel(scale * x);kernel_width = kernel_width/比例;别的% 无抗锯齿;使用未修改的内核.h = 内核;结尾

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

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

我的比例是 0.5
核是立方的.

但除此之外还有什么意义呢?我认为这就像创建一个稍后会调用的函数?

解决方案

imresize 在缩小图像时通过简单地扩大三次内核而不是离散的预处理步骤来实现抗锯齿.

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

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

立方核在imresize.m的底部定义为:

函数 f = cube(x)% 参见 Keys,数字图像的三次卷积插值% 处理",IEEE 声学、语音和信号汇刊%处理,卷.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 ,它将是连续的并且具有连续的一阶导数.OpenCV 似乎使用 -0.75.

但是,如果您编辑 [OPENCV_SRC]modulesimgprocsrcimgwarp.cpp 并更改代码:

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

到:

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]modulesimgprocsrcimgwarp.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天全站免登陆