How to avoid image display artifacts in Matlab?

后端 未结 2 652
既然无缘
既然无缘 2020-12-20 20:54

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

相关标签:
2条回答
  • 2020-12-20 21:26

    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.

    enter image description here

    enter image description here

    enter image description here

    0 讨论(0)
  • 2020-12-20 21:29

    As has been mentioned, MATLAB uses a nearest-neighbor interpolation for both upsampling and downsampling images for display. Because the image window is user-resizeable, the artifacts due to this can change just by moving the window around.

    One solution is to write a wrapper class for image display that monitors window events and resizes using imresize to more accurately display the data to the screen. I've written such a class, and it's publicly available. I do image processing work all the time, and MATLAB's inbuilt display system is very irritating. I use this one:

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

    It's designed to be a drop-in replacement for image, and will properly resample the images.

    0 讨论(0)
提交回复
热议问题