thanking you in advance
Maoz
On the top of the figure there is a row of tools including a magnifying glass with zoom and unzoom. Regards ! Matt
If you want to know how to do it in code, I have a GUI and I placed on
that a slider called sldZoom, and a label txtInfo. When the user
clicks the slider to change the zoom, it executes this code:
% --- Executes on slider movement.
function sldZoom_Callback(hObject, eventdata, handles)
% hObject handle to sldZoom (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
zoomFactor = get(hObject,'Value');
axes(handles.axesImage);
zoom('out');
zoom(zoomFactor);
txtInfo = sprintf('Zoom Factor = %.2f (%d %%)\n\nOnce zoomed, you
can pan by clicking and dragging in the image.', zoomFactor, round
(zoomFactor * 100));
set(handles.txtInfo, 'String', txtInfo);
txtInfo = sprintf('Zoom Factor = %.2f\n\nOnce zoomed, you can pan by
clicking and dragging in the image.', zoomFactor);
set(handles.sldZoom, 'TooltipString', txtInfo);
txtZoom = sprintf('Zoom Factor = %.2f (%d %%)', zoomFactor, round
(zoomFactor * 100));
set(handles.txtZoom, 'String', txtZoom);
% if zoomFactor ~= 1
% else
% end
% Set up to allow panning of the image by clicking and dragging.
% Cursor will show up as a little hand when it is over the image.
set(handles.axesImage, 'ButtonDownFcn', 'disp(''This executes'')');
set(handles.axesImage, 'Tag', 'DoNotIgnore');
h = pan;
set(h, 'ButtonDownFilter', @myPanCallbackFunction);
set(h, 'Enable', 'on');
return;
% Sets up panning by clicking and dragging via the hand cursor.
function [flag] = myPanCallbackFunction(obj, eventdata)
% If the tag of the object is 'DoNotIgnore', then return true.
% Indicate what the target is
disp(['In myPanCallbackFunction, you clicked on a ' get(obj,'Type') '
object.'])
objTag = get(obj, 'Tag');
if strcmpi(objTag, 'DoNotIgnore')
flag = true;
else
flag = false;
end
return;
Hey Matt,
I know how to use it the way you described. I meant it to be controled by the user (as a part of the algorythm)
regards,
Maoz
Maoz
---------------------------------
I used GUIDE. Just put a slider on the window with a tag "sldZoom"
and view the callback. Paste my code into the callback function, then
add the function myPanCallbackFunction to handle click-and-drag
panning, and you should be ready to go.
Hey ImageAnalyst,
I tried to do what you told me but I still have a problem. I still get an error when I run it. I attached my code below. I will appreciate any help of yours:
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
handles.axesImage=imread('lena.gif');
imshow(handles.axesImage);
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function sldZoom_Callback(hObject, eventdata, handles)
% hObject handle to sldZoom (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
zoomFactor = get(hObject,'Value');
axes(handles.axesImage);
zoom('out');
zoom(zoomFactor);
txtInfo = sprintf('Zoom Factor = %.2f (%d %%)\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor, round(zoomFactor * 100));
set(handles.txtInfo, 'String', txtInfo);
txtInfo = sprintf('Zoom Factor = %.2f\n\nOnce zoomed, you can pan by clicking and dragging in the image.', zoomFactor);
set(handles.sldZoom, 'TooltipString', txtInfo);
txtZoom = sprintf('Zoom Factor = %.2f (%d %%)', zoomFactor, round(zoomFactor * 100));
set(handles.txtZoom, 'String', txtZoom);
% if zoomFactor ~= 1
% else
% end
% Set up to allow panning of the image by clicking and dragging.
% Cursor will show up as a little hand when it is over the image.
set(handles.axesImage, 'ButtonDownFcn', 'disp(''This executes'')');
set(handles.axesImage, 'Tag', 'DoNotIgnore');
h = pan;
set(h, 'ButtonDownFilter', @myPanCallbackFunction);
set(h, 'Enable', 'on');
return;
% --- Executes during object creation, after setting all properties.
function sldZoom_CreateFcn(hObject, eventdata, handles)
% hObject handle to sldZoom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% Sets up panning by clicking and dragging via the hand cursor.
function [flag] = myPanCallbackFunction(obj, eventdata)
% If the tag of the object is 'DoNotIgnore', then return true.
% Indicate what the target is
disp(['In myPanCallbackFunction, you clicked on a ' get(obj,'Type') 'object.'])
objTag = get(obj, 'Tag');
if strcmpi(objTag, 'DoNotIgnore')
flag = true;
else
flag = false;
end
return;
% --- 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
thanks a lot,
Maoz
Can you tell me the error message? Otherwise I'd have to build up the
GUI myself. I could maybe try that tomorrow (no time now) but since
it will be my first day back to work in 2 weeks I doubt I'll have
time.
You did put a slider on the GUI and changed the Tag property of it to
say sldZoom didn't you?
Hey again,
my m-file and the flp are both called untitled (that's not my real code, just to fix this problem before...)
The error message I get is:
??? Error using ==> axes
Invalid object handle.
Error in ==> untitled>sldZoom_Callback at 64
axes(handles.axesImage);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> untitled at 17
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
when I run the program I can see the pic and the slider but when I click on the slider I get the message above.
thank a lot!!!
in the OpenFcn and get it to display the image?
Set a break point in the function at that line and see what the value
of handles is. It should be a structure with a bunch of fields in it,
one of which should be axesImage.
Hey,
I set the break point the place you told me and the field axesImage exist in the handles structure and includes the image info.
Just because the handle exists in the handles structure doesn't necessarily
mean it's valid.
handles.axes1 = axes;
pause
close all
handles.axes1
axes(handles.axes1)
--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
Then with this m-file, it will work as described:
function varargout = zoomtest(varargin)
% ZOOMTEST M-file for zoomtest.fig
% ZOOMTEST, by itself, creates a new ZOOMTEST or raises the
existing
% singleton*.
%
% H = ZOOMTEST returns the handle to a new ZOOMTEST or the handle
to
% the existing singleton*.
%
% ZOOMTEST('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in ZOOMTEST.M with the given input
arguments.
%
% ZOOMTEST('Property','Value',...) creates a new ZOOMTEST or
raises the
% existing singleton*. Starting from the left, property value
pairs are
% applied to the GUI before zoomtest_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to zoomtest_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows
only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help zoomtest
% Last Modified by GUIDE v2.5 05-Jan-2010 10:39:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @zoomtest_OpeningFcn, ...
'gui_OutputFcn', @zoomtest_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before zoomtest is made visible.
function zoomtest_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to zoomtest (see VARARGIN)
% Choose default command line output for zoomtest
handles.output = hObject;
% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
axes(handles.axesImage);
imshow(grayImage, []);
title('Original Grayscale Image');
% Set up zoom slider
minZoom = get(handles.sldZoom, 'min')
maxZoom = get(handles.sldZoom, 'max')
set(handles.sldZoom, 'value', minZoom);
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes zoomtest wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = zoomtest_OutputFcn(hObject, eventdata, handles)
function [flag] = myPanCallbackFunction(obj, eventdata)
% If the tag of the object is 'DoNotIgnore', then return true.
% Indicate what the target is
disp(['In myPanCallbackFunction, you clicked on a ' get(obj,'Type') '
object.'])
objTag = get(obj, 'Tag');
if strcmpi(objTag, 'DoNotIgnore')
flag = true;
else
flag = false;
end
return;
% --- Executes during object creation, after setting all properties.
Maoz