Image Processing: Zoom in, process image, zoom out

I am writing a GUI in which a user can apply some basic image processing (adjust brightness, contrast and thresholding) to an image file. Right now, I'm trying to figure out how to do a simple three step operation like:
1) Zoom in on image
2) process image (i.e. thresholding), while zoomed
3) Zoom out of image
I already managed to program steps 1) and 2), and it works quite good. Unfortunately I can't zoom out of the image after processing it. This is the code:
1) Zoom in
function zoomIn_OnCallback(hObject, eventdata, handles)
% hObject handle to zoomIn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global origXLim origYLim
zoomIn = zoom;
% save original axes limits
origXLim = get(handles.procAxes,'XLim');
origYLim = get(handles.procAxes,'YLim');
% get axes limits after zooming
set(zoomIn,'ActionPostCallback',@mypostcallback);
function mypostcallback(obj,evd)
global newXLim newYLim
newXLim = get(evd.Axes,'XLim');
newYLim = get(evd.Axes,'Ylim');
2) Image processing (here thresholding with a slider)
% --- Executes on slider movement.
function threshSlider_Callback(hObject, eventdata, handles)
% hObject handle to threshSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global newXLim newYLim
% get slider value
value = get(hObject, 'Value');
% display Slider value
set(handles.threshValue, 'String', num2str(value));
% thersholding (selfwritten function)
handles.newImg = threshold(handles.procImg, value, handles.color);
% display on axes for processed image
axes(handles.procAxes);
imshow(handles.newImg);
set(handles.procAxes, 'XLim', newXLim);
set(handles.procAxes, 'YLim', newYLim);
% update handles structure
guidata(hObject, handles);
I actually know, that I can't zoom out to the original size of the image, because I have set the limits of the axes that display the image to the new values 'newXLim' and 'newYLim'. But I just don't know an other way to keep the "zoomed in" state while applying the thresholding to the image. Is there maybe another way to do this?

 採用された回答

Walter Roberson
Walter Roberson 2015 年 9 月 22 日

0 投票

Instead of using imshow at that point, update the Cdata property of the image object. You should not need to set the axis xlim or ylim when you do that.

2 件のコメント

Phillip Probst
Phillip Probst 2015 年 9 月 22 日
Thank you very much, Walter!
This actually solves everything and shortens my code. Just perfect!
Best Regards
Phillip
Maria Avila
Maria Avila 2017 年 12 月 18 日
I have been trying to do a very similar program to yours and I have been having troubles with the zoom. I have been able to perform zoom on a set of images with the code you gave, but I have been having troubles understanding what do you mean by "update the Cdata property of the image object". How can I do that?

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 9 月 22 日

0 投票

Attached is the Mathworks demo for zooming.

カテゴリ

ヘルプ センター および File ExchangeDisplay Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by