How to avoid image display artifacts in matlab?

When I display a bitmap using image in the Matlab shape window, I experience strange artifacts:

I mean the cruciform structures, which are especially noticeable at the edges of a section of the brain, but are present throughout.

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

enter image description here

I assume that the artifacts are associated with a little scaling, which is necessary to match the image with the given axis size.

Does anyone have any ideas on how to avoid these artifacts? I tried to change the number of 'Renderer' , which really affects the artifact, but does not allow it to disappear.


How to reproduce the effect:

  • save the second image as "image.png"

  • execute:

     im = imread('image.png'); image(im) set(gca, 'Units', 'pixels') set(gca, 'Position', [76.1094204520027 576.387782501678 343.969568136048 357.502797046319]) 
  • enlarge the figure window so that the axes with the image become visible.

The dimensions of the native image are 306 x 318, but it is displayed at about 344 x 358 pixels.


I conducted several further experiments and found that the effect is not specific to this image, specific positioning or color map:

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

gives

for a certain size, the picture window shows the same kind of artifacts.

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

+6
source share
2 answers

It seems to me that the artifacts are caused by the fact that Matlab interpolates to translate the pixels of the image into the pixels of the screen.

It would be nice to change the interpolation method used by Matlab when displaying the image, but this is not possible (changing 'renderer' does not help). Thus, you can manually interpolate the image according to the size of the screen, and then display this interpolated image, for which one pixel of the image now corresponds to one pixel of the screen. Thus, Matlab does not need to be interpolated.

To do the interpolation, I used the imresize function. I find that all available interpolation methods give more or less the same results, except for 'box' , which is even worse than automatic interpolation using Matlab. I am applying some results:

  • The first image is obtained with your approach. You can see artifacts in the 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 mn]) 
  • The second image uses manual interpolation using imresize using the 'box' option. Artifacts are similar or even more pronounced.

     imr = imresize(double(im)/255, [mn], '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 mn]) 
  • The third digit is the second, but with the parameter 'bilinear' . Artifacts are very weak, although they are still visible in some parts. Other interpolation methods give similar results.

enter image description here

enter image description here

enter image description here

+6
source

As already mentioned, MATLAB uses nearest neighbor interpolation for upsampling and downsampling images for display. Since the image window is resized by the user, artifacts associated with this can only be changed by moving the window around.

One solution is to write a wrapper class to display the image, which controls window events and resizes using imresize to more accurately display data on the screen. I wrote such a class, and it is publicly available. I process image processing all the time, and the MATLAB built-in display system is very annoying. I use this one:

http://www.mathworks.com/matlabcentral/fileexchange/46051-rviewer

It is intended to be replaced by image and will correctly reprogram images.

+1
source

Source: https://habr.com/ru/post/973900/


All Articles