Steve on Image Processing with MATLAB

Image processing concepts, algorithms, and MATLAB

如何显示具有双线性插值和抗锯齿的图像

Note: this blog post describes an image display feature that is new in R2019b. You can download this release from//www.tatmou.com/downloads.

这是my new favorite image:

But that's just a 512x512 version of it. Click这里对于全分辨率(2048x2048)版本。Image credit: DeFacto [CC BY-SA 4.0 (https://creativeCommons.org/licenses/by-sa/4.0.

This image caught my eye because I'm always looking for a good sample image to demonstrate混叠。此外,我想在R2019B中编写关于新的MATLAB图像显示功能的博客文章:Bilinear插值和抗锯齿。

Before I get into image display details, though, let's zoom into the center of the full-resolution image to see why it interests me.

URL =.'//www.tatmou.com/blogs/steve/files/Decimal_Clock_face_by_Pierre_Daniel_Destigny_1798-1805.jpg';a = imread(URL);a_cropped = a(( -  250:250)+ 1024,(-250:250)+ 1024,:);imshow(a_cropped)

接下来,我想沿着显示高频空间变化的路径计算像素轮廓。下面的代码显示了蓝色的路径。

holdx = [120 80]; y = [106 188]; plot(x,y,'b','LineWidth',4) hold离开

这里是沿着该路径沿着该路径的像素配置文件(转换为灰度)。

close全部c = improfile(A_cropped,x,y); c = rgb2gray(squeeze(c)/255); h = plot(c(:,1)); xlabel('Distance along the profile path')ylabel('Gray-scale pixel value')DataTip(H,13,0.9614);DataTip(H,25,0.9271);DataTip(H,60,0.9282);DataTip(H,72,0.9133);

我已经放置了一些数据,以表明沿着路径的空间周期是大约4个像素单元。这是very close到可以用该像素间隔表示的最高空间频率。换句话说,它非常接近我所说的话critically sampled

Why does this matter? Well, it means that if you shrink this image down just by using nearest-neighbor interpolation, which is the way MATLAB has always displayed images previously, you'll see some strange artifacts. Below, I'll useimshow.to display the image at 25% magnification.

imshow.(A_cropped,'InitialMagnification',25)

With R2019b, though, you can specify that you want an image to be displayed using bilinear interpolation. And, as explained in the documentation, when bilinear interpolation is specified, MATLAB also automatically applies an antialiasing technique.

imshow.(A_cropped,'InitialMagnification',25,'插值','bilinear')

You can still see some spatial artifacts in this result, but they are significantly reduced.

Now let's examine the effect of specifying bilinear interpolation when you magnify an image instead of shrinking it. First, I'll crop out an even smaller piece of the original image.

B_cropped = A_cropped(50:150,115:215,:); imshow(B_cropped)

Next, let's display it with 500% magnification, with and without the bilinear interpolation option.

imshow.(B_cropped,'InitialMagnification',500) title('500% magnification using nearest-neighbor interpolation')
imshow.(B_cropped,'InitialMagnification',500,'插值','bilinear') 标题('500% magnification using bilinear interpolation')

You can see the improved quality in the version using bilinear interpolation.

注意,默认仍恩颐投资rest-neighbor interpolation. This was a choice that we discussed at some length. Ultimately, we decided to leave the default behavior unchanged, for two reasons:

  • 避免不兼容
  • 对于某些图像阵列,例如包含分段标签或其他类型的类别,Bilinear插值不合适

If you already have MATLAB R2019b, give this image display option a try and let me know what you think in the comments.




Published with MATLAB® R2019b

|
  • print
  • send email

评论

To leave a comment, please click这里to sign in to your MathWorks Account or create a new one.