Can I change the interpolation used in images shown in a GUI?
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
vijaya lakshmi
2018년 4월 10일
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
Walter Roberson
2018년 4월 10일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!