store image in a handle.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohamed Amine Henchir
el 9 de Oct. de 2018
I'm creating a GUI with a bunch of call back functions, the idea is to load an image an do a series of image transformation to it, I would like to keep those changes to the image and pass it around from one call back function to the other, I looked around to see if there is a similar case, even though there was plenty I couldn't figure out what's wrong with my code.
if true
% function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
guidata(hObject, handles);
img = get(handles.edit1,'String');
I = imread(img);
guidata(handles.figure1,I);
imshow(I);
disp(handles.figure1);
% --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) guidata(hObject, handles); h =findobj(0,'tag','figure1'); imshow(h); end
1 comentario
Stephen23
el 10 de Oct. de 2018
Editada: Stephen23
el 10 de Oct. de 2018
This first line of code inside the callback serves no purpose:
guidata(hObject, handles);
handles is supplied by GUIDE as the third input argument to your function. There is absolutely no point in saving it straight away, without having made any changes or addition to it. Totally pointless.
Respuesta aceptada
Stephen23
el 10 de Oct. de 2018
Editada: Stephen23
el 10 de Oct. de 2018
When you save I using guidata you replace the handles structure with I, and so handles does not exist any more (and hence none of its values or graphics handles exist either). Instead of throwing handles away, you should store your data as a field of the handles structure:
handles.I = imread(img);
guidata(hObject,handles);
This is exactly what all of the guidata examples show, which is why you should read the documentation.
6 comentarios
Stephen23
el 11 de Oct. de 2018
Editada: Stephen23
el 12 de Oct. de 2018
This will not work:
h = imcontrast(handles.figure1);
The first input to imcontrast is described in its help as "...the image specified by the handle h". You are giving it the handle to some figure object. A figure object is not an image object. You need to provide it with a handle to the image object, just like the help explains.
This will not work:
waitfor(h)
I = get(h,'CData');
When you read the waitfor help it states that it "...blocks statements from executing until the MATLAB® object closes (is deleted)". So the code will continue once the imcontrast dialog box is closed. But once an object has been deleted you cannot get any properties from it, so you cannot expect to get anything out of an object that no longer exists. Note that a figure object does not have the property 'CData', so this would never work anyway: you need to give it the handle to the image.
Summary: Provide the image handle to imcontrast, as its help requires. To get the image data from the image replace the h with the image handle which is returned by imshow.
imh = imshow(handles.I);
dbh = imcontrast(imh);
waitfor(dbh)
I = get(imh,'CData');
Tip: you should read the documentation for every function that you use. I also recommend that you obtain and use the graphics handles for every graphics object that you need to refer to:
Más respuestas (0)
Ver también
Categorías
Más información sobre Explore and Edit Images with Image Viewer App en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!