Borrar filtros
Borrar filtros

Resize using GUI(Axis) not correct type...

1 visualización (últimos 30 días)
JR
JR el 20 de Feb. de 2015
Respondida: Geoff Hayes el 22 de Feb. de 2015
I have a GUI, where the image is loaded in and displayed in an axis. I need to resize the image (handles.axes1) using the input arguments (ImageHeight,ImageWidth). The code prior to this point works without error. But when it gets to the code below, it gives this error:
AdjustedImage = imresize(handles.axes1,[ImageHeight,ImageWidth]);
*Error using imresize
Expected input number 1, A, to be one of these types:
numeric, logical
Instead its type was matlab.graphics.axis.Axes.
Error in imresize>parsePreMethodArgs (line 333)
validateattributes(A, {'numeric', 'logical'}, {'nonsparse', 'nonempty'}, mfilename, 'A', 1);*
How would I be able to resize, using the input Height and Width?
Thanks.

Respuestas (1)

Geoff Hayes
Geoff Hayes el 22 de Feb. de 2015
JR - your first input to the imresize function is the handle to the axes1 object and isn't an image which is required by the re-sizing function. In order to get around this, you can try the following - save the image to the handles structure (whenever you load it), do the resize on this image, and then show the resized image in the axes.
Suppose that you load the image in the OpeningFcn of your GUI. You could do something like
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% load the image
myImg = imread('someImg.jpg');
% display the image in the axes
image(myImg,'Parent',handles.axes1);
% add the image to the handles structure
handles.myImg = myImg;
% update the handles structure
guidata(hObject, handles);
Now, in your callback that does the resizing, just do this
% resize the image
AdjustedImage = imresize(handles.myImg,[ImageHeight,ImageWidth]);
% show the image in the axes
image(AdjustedImage,'Parent',handles.axes1);
In the above I used image rather than imshow because I don't have the Image Processing Toolbox, so you can use whichever is convenient. Try implementing the above and see what happens!

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by