how to load image in different axes(axes1,axes2,axes3) using single pushbutton???...

2 次查看(过去 30 天)
I have to use two axes and two pushbutton to load the image.
_% --- Executes on button press in imagebtn.
function imagebtn_Callback(hObject, eventdata, handles)
[baseFileName,folder]=uigetfile('*.*','Specify an image file','on');
fullimageFileName=fullfile(folder,baseFileName);
axes1=imread(fullimageFileName);
axes(handles.axes1);
image(axes1)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
[baseFileName,folder]=uigetfile('*.*','Specify an image file','on');
fullimageFileName=fullfile(folder,baseFileName);
axes2=imread(fullimageFileName);
axes(handles.axes2);
image(axes2)._
But I saw the code for load different image using single button program source code in matlab. But sure I am not understand that code in some line in that program. I used that code But so many error occured. Reason i am not tell properly how to handle the axes. how to give the Tag name for Axes. For Example
[File,Folder]=uigetfile('*.*','Multiselect','on');
% i think this the probles
handles.img=cell(1,length(File)); % what puropse using that img(handles.img)
for iFile=1:length(File)
filename=fullfile(Folder,File{iFile});
image=imread(filename);
axes(handles.axes{iFile});
imshow(image);
handles.img{iFile}=image;
end guidata(hObject,handles);
I got Following Error.
??? Cell contents reference from a non-cell array object.
Error in ==> Clrc>pushbutton2_Callback at 119 filename = fullfile(Folder, File{iFile});
Error in ==> gui_mainfcn at 96 feval(varargin{:});
Error in ==> arambam at 42 gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)arambam('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

采纳的回答

Image Analyst
Image Analyst 2013-2-6
Well, . . . they're both bad. the first set of code calls the image array axes1 and axes2 - the same name that you're calling the axes. While this won't give an error it is confusing and bad practice. You should call them grayImage or rgbImage or some other descriptive name that's not the name of one of your GUI controls. You can use the same name in both functions since you seem to be keeping the image just as a local variable, local to that function and it vanishes when that function exits.
The second set of bad code overwrites the built in image() function by calling the image array "image" - again, very very bad practice. You never want to choose a variable name that is the same name as one of the built in functions.
But the reason for the error is this expression:
handles.axes{iFile}
handles is a structure. It does not have a structure member (field) called "axes", much less one that is a cell array. If you were to want to do it that way, you'd have to use dynamic structure names, but that is complicated and confusing. If you have only a handful of axes to populate with images, then I'd recommend just setting the current axes with the axes() function, or with the 'parent' option of imshow(). If you will really have some variable number of axes, like dozens, then I'd recommend you create them on the fly with uicontrol() and get the handles into an array. Then you could index them in a loop.
  2 个评论
ChristianW
ChristianW 2013-2-6
编辑:ChristianW 2013-2-6
The Function findobj can also be used:
h = findobj(handles.figure1,'Type','axes');
for i = 1:2
pics{i} = imread('ngc6543a.jpg');
image(pics{i},'parent',h(i))
end
Image Analyst
Image Analyst 2013-2-6
Yes, very nice. As long as the axes are arranged in the desired order/layout on the GUI, this will work nicely.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by