Can I change the interpolation used in images shown in a GUI?
4 views (last 30 days)
Show older comments
I often display images in a resizable GUI. The interpolation used on the image to make it fit in the specified axis provides poor results- blocky with discontinuities. Looks like nearest neighbour. Can I alter this to bilinear or bicubic? To see this run:
img = zeros(512);
for n=1:512
img(n,n) = 1;
end
h = imshow(img);
and now resize the GUI.
0 Comments
Answers (1)
vijaya lakshmi
on 10 Apr 2018
Hi Andrew
The image quality reduces while resizing a GUI window containing an axes which in turn contains the image. There is a workaround for this:
GUIDE has been used to build the GUI. Let's say the Tag name for the figure window is 'figure1'. Let this figure window contain the axes - axes1. You can use the callback function - figure1_SizechangedFcn of figure1 as follows:
im=imread('myimage.jpg');
axes(handles.axes1);
handles.axes1.Units='Pixels';
pos=get(handles.axes1,'Position');
handles.axes1.Units='normalized';
im_resized=imresize(im,[pos(4) pos(3)]);
imshow(im_resized,'Parent',handles.axes1);
1. As can be seen from the code above, the units of the axes needs to be changed to 'Pixels' in order to obtain the size of the newly resized axes in pixels. The default value is 'Normalized'. Now this information will used in the imresize function to resize the image appropriately.
2. Following this, the units of the axes has been changed back to 'Normalized'. This is due to fact that, while resizing a figure window, the axes within that figure window gets autoresized only if the units of the axes is set to 'Normalized'. This is required since we want the axes to get resized by resizing the window.
3. Now, the image within the resized axes can be resized using the pixel position information obtained before and by using the imresize function.
The imresize uses some interpolation methods to properly resize the image. The default interpolation method is 'bicubic'. One can try other methods to obtain different results. Please go through this documentation link
1 Comment
Walter Roberson
on 10 Apr 2018
However if you resized larger later then you would have the original problem. So you would want to hook into the figure resize callback to trigger an imresize that you then dropped in the axes. You would also want to hook into the zoom/pan callbacks for the axes.
See Also
Categories
Find more on Visual Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!