How do i zoom into a specific XY location?

6 views (last 30 days)
Tristan G
Tristan G on 7 Apr 2017
Answered: Image Analyst on 7 Apr 2017
I have loaded an image into axes and created a contextmenu (right-click menu). When I right click my mouse the menu appears with zoom options such as zoom in and zoom out.
GOAL: When I right click and click "Zoom In" I want to zoom into the location where I right clicked.
EX: zoom(factor, x, y)
MY CODE:
% --------------------------------------------------------------------
function importImage_Callback(hObject, eventdata, handles)
% hObject handle to importImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%global im im2
filename = uigetfile({'*.jpg;*.jpeg;*.tif;*.png;*.gif','All Image Files';});
global im im2
im = imread(filename);
im = im2double(im); %Conver to double
im2 = im; %backup process
imshow(im,'Parent', handles.axes1)
image(im,'hittest','off')
function digitize_Callback(hObject, ~, handles)
% hObject handle to digitize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ng=0;
nXY = [];
n=0;
[writefname, writepname] = uiputfile('*.txt','Save data as');
writepfname = fullfile(writepname, writefname);
fid = fopen(writepfname,'wt');
while 1
[x,y, buttonNumber] = ginput(1);
if buttonNumber == 1,
line(x,y,'Marker','.','Color','r','MarkerSize',12)
sn = num2str(n + 1);
text(x,y, sn)
n = n+1;
disp(sprintf(' %4d %f %f',n, x, y))
ng = ng+1;
nXY(ng,:) = [n x y];
fprintf(fid,'%g,%g,%g\n',n, x, y);
elseif buttonNumber ~= 3
query = questdlg('STOP digitizing and QUIT ?', ...
'DIGITIZE: confirmation', ...
'YES', 'NO', 'NO');
drawnow
switch upper(query),
case 'YES',
disp(sprintf('\n'))
break;
%case 'No',
end % switch query
end
end
fclose(fid);
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --------------------------------------------------------------------
function update_points_Callback(hObject, eventdata, handles)
% hObject handle to update_points (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[FileName,PathName] = uigetfile('*.txt');
eval(['!notepad ' PathName FileName])
% --------------------------------------------------------------------
function zoom_in_Callback(hObject, eventdata, handles)
% hObject handle to zoom_in (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
zoom(2)
% --------------------------------------------------------------------
function zoom_out_Callback(hObject, eventdata, handles)
% hObject handle to zoom_out (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
zoom(.5)
% --------------------------------------------------------------------
function zoom_pixel_Callback(hObject, eventdata, handles)
% hObject handle to zoom_pixel (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
zoom(100)
% --------------------------------------------------------------------
function full_view_Callback(hObject, eventdata, handles)
% hObject handle to full_view (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
zoom out
% --------------------------------------------------------------------
function zoom_Callback(hObject, eventdata, handles)
% hObject handle to zoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Answers (1)

Image Analyst
Image Analyst on 7 Apr 2017
See this attached demo from the Mathworks.

Categories

Find more on Visual Exploration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!