From: Ravi Rastogi on
Hi guys,

I am trying to make a code that will help allow the user to zoom at different factor values. So for example, we have displayed any image using imshow, then when the user clicks the left button it should zoom in and when he clicks right button it should zoom out to the last zoomed value and when he clicks on the scroll wheel the figure should close.

Here is how i am doing it, (not the most efficient way)

load RoadMap;
figure; imshow(~matrix);
stoploop=0;
bclick=1; % Button click no, zoom level
while stoploop
w = waitforbuttonpress;
if w == 0
disp('Button click');
[Xclick Yclick button]=ginput(1);
end
%Button press: left : zoom in
if button==1;
title('Zoom IN button click');
zoom on;
fac=bclick+1;
zoom(fac);
end;

%Button press: right : zoom out
if button==3,
title('Zoom OUT button click');
bclick=bclick-1;
set(zoom,'Direction','out');
zoom(bclick);
end;

%Buttom press: Middel : Abort
if button==2,
stoploop=1;
close all;
end;
end;

When i do this the image is always zoomed at the center of the image, but i want to the image to be zoomed at the button click position (Yclick, Yclick), how can i do that?
Zoom out part is not working, how can i make the image zoom out to the last zoomed position?
Is there a better way to detect button clicks of the mouse rather than using ginput?

Thanks
ravi