不可估量的双线性MATLAB [英] imresize bilinear MATLAB

查看:62
本文介绍了不可估量的双线性MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用MATLAB调整图像的大小,而对于使用双线性模式的imresize函数直接了解是有些奇怪的事情.

I try to resize an image with MATLAB and there was something strange to understand directly about imresize function with bilinear mode.

我将向您提供示例,以确保出现问题. 说,以下是一维矩阵.

I will give you examples to make sure what's the problem. Say, the followings are 1D-matrix.

A: [0 1 2]
B: [1 2 0 5]

据我所知,将A缩放为1D数组中的[1,5]的线性插值可以实现

the linear interpolation of scaling A to [1,5] in 1D array, so far as I know, makes

A: [0, 0.5, 1, 1.5, 2]

但是,从MATLAB

However, from MATLAB,

imresize(A,[1,5],'bilinear')

显示

[0, 0.4, 1, 1.6, 2.0]

imresize(B,[1,5],'bilinear')
imresize(B,[1,10],'bilinear')

每个,显示

[1.0 1.7 1.0 1.5 2.0]
[1.0 1.1667 1.16111 1.8889 1.0000 0.1111 1.9444 4.1667 5.0000]

我从不同的论坛上发现了很多问题和答案,但从总体上看,没有一个让我感到满意.

I found a lot of questions and answers from different forums and none of them makes me be satisfied, in terms of generality.

但是,我在'imresize.m'的一行代码中找到了答案,

However, I found the answer from a line of code in 'imresize.m',

u = x/scale + 0.5 * (1-1/scale)

其中,u确定输出矩阵的索引.通过上面的内容,我意识到imresize with bilinear

where u determines the index of output matrix. From the above, I realize how the strange outputs are made by imresize with bilinear

但是问题是, 我不明白0.5 * (1-1/scale)的含义.

But the question is, I don't understand the meaning of 0.5 * (1-1/scale).

没有0.5 * (1-1/scale)u = x/scale显示可以输出的原始算法

Without 0.5 * (1-1/scale), u = x/scale shows the original algorithm which can output

A: [0, 0.5, 1, 1.5, 2],它是真正的线性.

然后,为什么我们需要术语0.5 * (1-1/scale)?目的和意义是什么?

Then, why do we need the term 0.5 * (1-1/scale)? What is the purpose and meaning?

推荐答案

假设您的图片是A = [0 1 2];因此我们可以将图像像素的结构可视化为

Assume that your image is A = [ 0 1 2]; so we can visualize the structure of image pixels as

     _________ _________ _________ 
    |         |         |         |
    |    0    |    1    |    2    |
    |_________|_________|_________|

    0   0.5   1   1.5   2   2.5   3

其x坐标范围为0到3,并且假定像素值的位置在其中心.

That its x coordinates ranges from 0 to 3 and position of value of the pixel is assumed in the center of it.

当我们要将图像调整为5像素时,我们应该找到应该从原始图像中提取值的位置. 为此,我们将[0:5]乘以3/5.

When we want to resize the image to 5 pixels we should find where the values should be extracted from the original image. For it we multiply [0:5] by 3/5.

     _____ _____ _____ _____ _____ 
    |     |     |     |     |     |
    |     |     |     |     |     |
    |_____|_____|_____|_____|_____|

    0    3/5   6/5   9/5   12/5   3

要找到像素中心的位置,我们将([0:4] + .5)乘以3/5

To find position of center of pixels we multiply ([0:4] + .5) by 3/5

((0:4) + .5) * 3/5

ans = 
    0.3   0.9   1.5   2.1   2.7

因此,例如,要在缩放图像中找到第二个像素的值,我们应该参考原始图像中的位置0.9,然后提取(插值)该像素的值为0.4.

So for example to find value of the second pixel in the scaled image we should refer to position 0.9 in the orginal imaged and extract(interpolate) value of the pixel which is 0.4.

     _____ _____ _____ _____ _____ 
    |     |     |     |     |     |
    |     | 0.4 |  1  | 1.6 |     |
    |_____|_____|_____|_____|_____|

      0.3   0.9   1.5   2.1   2.7  

第一个像素和最后一个像素的值(通常是位置超过[0.5-2.5]的那些像素)分别设置为与原始图像的第一个像素和最后一个像素相同.

Value of the first and the last pixels(and generally those pixels that have positions beyond [0.5-2.5]) are set the same as the first and the last pixels of the original image respectively .

     _____ _____ _____ _____ _____ 
    |     |     |     |     |     |       
    |  0  | 0.4 |  1  | 1.6 |  2  |
    |_____|_____|_____|_____|_____|

这篇关于不可估量的双线性MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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