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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Image Analyst
Image Analyst le 6 Fév 2013
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 commentaires
ChristianW
ChristianW le 6 Fév 2013
Modifié(e) : ChristianW le 6 Fév 2013
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 le 6 Fév 2013
Yes, very nice. As long as the axes are arranged in the desired order/layout on the GUI, this will work nicely.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by