如何避免Matlab中的图像显示失真? [英] How to avoid image display artifacts in Matlab?

查看:1369
本文介绍了如何避免Matlab中的图像显示失真?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Matlab图形窗口中使用 image 显示位图图像时,我遇到了奇怪的工件:



我指的是这些十字形结构在脑切片的边缘特别可见,但始终存在。

这些结构不在底层图像数据中,它们完全相同以下图片中的内容:





我假设工件必须与将图像与给定坐标轴大小匹配所需的轻微缩放比例相匹配。



有人有一个想法如何避免这些文物?我尝试改变数字'Renderer',这确实会影响神器,但不会消失。






如何重现效果:


  1. 将第二张图像另存为图像

  2. ( 'image.png');
    image(im)
    set(gca,'Units','pixels')
    set(gca,'Position',[76.1094204520027 576.387782501678 343.969568136048 357.502797046319])
  3. 使图形窗口最大化,以便带图像的轴线变得可见


原始图片尺寸为306 x 318,但显示尺寸约为344 x 358像素。






我做了一些进一步的实验,发现效果不是特定于此图片,特定位置或颜色映射:

  [x,y] = meshgrid(-1:0.01:1); 
imagesc(cos(10 * sqrt(x。^ 2 + y。^ 2)))





对于图形窗口的特定尺寸显示相同类型的工件。



知道人造物是特定于我的Matlab版本(2013a)或平台(Debian Linux,带有NVidia图形的内核3.14)。

就好像这些伪像是由Matlab 插值将图片像素转换为屏幕像素一样。



如果能够更改插值Matlab在显示图像时使用的方法,但似乎不可行(更改'renderer'不起作用)。因此,您可以手动插入图像以匹配显示大小,然后显示该插值图像,其中一个图像像素现在对应于一个屏幕像素。这种方式Matlab不必插入。



为了完成插值,我使用了 imresize 功能。我发现除了'box'之外,所有可用的插值方法或多或少都会得到相同的结果,这比Matlab的自动屏幕插值更差。我附上了一些结果:


  • 第一张照片是用你的方法获得的。您可以在其左右边缘以及较低的内部对角线边缘看到伪影。代码:

      m = 344; 
    n = 358;
    image(im)
    set(gca,'units','pixels','Position',[40 40 mn])
    imresize 使用'box'手动插值 $ c>选项。

      imr = imresize(double(im)/ 255,[mn],'框'); %//转换为double和
    %//插入到大小[m,n]
    图像(imr / max(imr(:)))%//显示图像大小与显示大小相匹配的大小。
    %//标准化是必需的,因为插值可以给出值
    %//超出区间[0 1]
    set(gca,'units','pixels','Position' ,第[40 40 mn])


  • $ c>'bilinear'选项。这些文物是非常衰减的,尽管在某些部分仍然可见。其他插值方法给出了类似的结果。









When I display a bitmap image using image in a Matlab figure window, I'm experiencing strange artifacts:

What I'm referring to are the cross-shaped structures which are particularly visible at the edges of the brain slice, but present throughout.

These structures are not in the underlying image data, which are exactly identical to those in this image:

I assume the artifacts have to do with the slight rescaling that is necessary to match the image to the given axes size.

Does someone have an idea how to avoid these artifacts? I tried changing the figure 'Renderer', which does indeed affect the artifact, but does not let it vanish.


How to reproduce the effect:

  1. save the second image as "image.png"

  2. execute:

    im = imread('image.png');
    image(im)
    set(gca, 'Units', 'pixels')
    set(gca, 'Position', [76.1094204520027 576.387782501678 343.969568136048 357.502797046319])
    

  3. maximize the figure window, so that the axes with the image becomes visible

Native image dimensions are 306 x 318, but it is displayed at about 344 x 358 pixels.


I did some further experiments and found that the effect is not specific to this image, the particular positioning, or the colormap:

[x, y] = meshgrid(-1:0.01:1);
imagesc(cos(10*sqrt(x.^2 + y.^2)))

giving

for a specific size of the figure window shows the same kind of artifacts.

It would be interesting to know whether the artefact is specific to my Matlab version (2013a) or platform (Debian Linux, kernel 3.14 with NVidia graphics).

解决方案

It looks to me as if the artifacts are caused by Matlab interpolating to translate picture pixels into screen pixels.

It would be nice to be able to change the interpolation method used by Matlab when displaying the image, but that doesn't seem to be possible (changing 'renderer' doesn't help). So you could manually interpolate the image to match the display size, and then display that interpolated image, for which one image pixel now corresponds to one screen pixel. That way Matlab doesn't have to interpolate.

To do the interpolation I've used the imresize function. I find all available interpolation methods give more or less the same results, except 'box', which is even worse than Matlab's automatic screen interpolation. I attach some results:

  • First picture is obtained with your approach. You can see artifacts in its left and right edges, and in the lower inner diagonal edges. Code:

    m = 344;
    n = 358;
    image(im)
    set(gca, 'units', 'pixels', 'Position', [40 40 m n])
    

  • Second picture applies manual interpolation with imresize using 'box' option. The artifacts are similar, or even more pronounced.

    imr = imresize(double(im)/255, [m n], 'box'); %// convert to double and 
    %// interpolate to size [m, n]
    image(imr/max(imr(:))) %// display with image size matching display size.
    %// Normalization is required because the interpolation may give values
    %// out of the interval [0 1]
    set(gca, 'units', 'pixels', 'Position', [40 40 m n])
    

  • Third figure is as the second but with 'bilinear' option. The artifacts are very attenuated, although still visible in some parts. Other interpolation methods give similar results.

这篇关于如何避免Matlab中的图像显示失真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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