Why can't MATLAB resize an image nicely?

16 views (last 30 days)
So I have an image with some text on it that I want to display in MATLAB for whatever reason, sounds easy enough, but it turns out that for some reason I hope to find out, MATLAB is apparently awful at rendering images to actually look nice.
I have a feeling there are performance reasons for this, but it seems like users should be able to resize an image with text on it and still actually read the image.
I have attached a sample image showing the original image, a highly distorted but still readable version of the image in Microsoft Word, and then an ever so slightly distorted version of the image in MATLAB which still looks awful.
If anyone can either explain how to fix this, or why its unfixable and why I should like it that way, I would really appreciate it!

Accepted Answer

Alex Taylor
Alex Taylor on 16 May 2013
Would you please provide some code as to how you are displaying, resizing, and exporting the data from MATLAB so that we can better understand what you are trying to do?
One thing I would try is that I suspect you are using image/imagesc instead of imshow to display that data. If you aren't careful with the data aspect ratio in your axes, this will distort the text in display. If you cannot use imshow (IPT dependency), try this:
A = imread('http://www.antigrain.com/research/font_rasterization/msword_text_rendering.png');
This will display your data at the original aspect ratio, which is definitely something you need when working with text.
Shaun VanWeelden
Shaun VanWeelden on 17 May 2013
I accepted your answer because I appreciate the help, I did kind of find a work around myself that delivers very high quality at the cost of performance. I did not know (or forgot) about image truesize though, very cool!

Sign in to comment.

More Answers (3)

Image Analyst
Image Analyst on 16 May 2013
Try using the 'nearest' option in imresize(). Though if a line is just one pixel in your image, it's either going to be there or not if you use nearest. If you use bicubic then you'll get partial intensity depending on how much of the output pixel lands on your input pixel.
Image Analyst
Image Analyst on 16 May 2013
Using nearest will give you sharper edges than bicubic, though at the cost of having jaggies on your edges and lines. Alex is the expert here so he would be able to help you more than me.

Sign in to comment.

Shaun VanWeelden
Shaun VanWeelden on 17 May 2013
A robust way I figured out how to do it was resize the image to 10x (or whatever you want, benefits seem to cut off at 8-10 times) its original size. When MATLAB puts the image into an axis of a different size than the original image (almost always), it looks MUCH MUCH better - granted this does kinda kill performance.
This would be very possible to do without the IPT, using interp2, its just not a simple one liner then.

DGM on 12 Apr 2022
For passers-by:
Normally, imshow() displays images using nearest-neighbor interpolation. That leads to thin features disappearing completely.
It wasn't available at the time of this post, but imshow() also supports bilinear display interpolation:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!