Running GUI shows last images in the axes - how to make the axes be empty

1 次查看(过去 30 天)
I built simple guide that shows image on axes.
When I restart the guide, I see the last image and the pressed pushbuttons (even thouth I exit the guide and re-entered, it looks like it continues from the last run and not reset itself).
I thought it related to global variables but it is not (I eliminated it and still has the same issue).
How to reset the guide?
Thx

回答(1 个)

Image Analyst
Image Analyst 2023-7-19
It should not be doing this but you forgot to attach your .fig and .m files. At the beginning of your OpeningFcn function put this:
clear global
cla(handles.axesImage); % or whatever tag you used for your image axes.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
  2 个评论
Ilan
Ilan 2023-7-20
Hi, thx
I put the line above and it seems to work but simultaneously, the line cla(handles.org_img); gives a lot of errors starting with:
"Error using matlab.graphics.primitive.Image/get
Invalid or deleted object.
Error in imagemodel/getClassType (line 342)
imageclass = class(get(imgmodel.ImageHandle,'CData'));
Error in imagemodel/getNumberFormatFcn (line 570)
imageClass = getClassType(imgmodel);
Error in imagemodel/getDataFromImageTypeFormatter (line 832)
[formatNumber, containsFloat] = getNumberFormatFcn(imgmodel);
Error in imagemodel/getDefaultPixelInfoString (line 365)
string = getDataFromImageTypeFormatter(imgmodel,'DefaultPixelInfoString');
Error in impixelinfoval/displayPixelInfo/displayDefaultString (line 193)
defaultPixelInfoString = getDefaultPixelInfoString(imageModels);
Error in impixelinfoval/displayPixelInfo (line 124)
displayDefaultString;"
...
The function is:
function varargout = img_analysis_gui(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @img_analysis_gui_OpeningFcn, ...
'gui_OutputFcn', @img_analysis_gui_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
function img_analysis_gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
clear global
cla(handles.org_img)
set(handles.cut_panel,'visible','off')
function varargout = img_analysis_gui_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function load_img_Callback(hObject, eventdata, handles)
global image
[org_img,path] = uigetfile({'*.tif';'*.tiff'});
image= imread([path org_img]);
axes(handles.org_img);
imagesc(image)
impixelinfo
function img_cut_Callback(hObject, eventdata, handles)
global image
if isempty (image)
f = errordlg( 'Load Image' , 'Error' );
return
end
set(handles.cut_panel,'visible','on')
function img_hist_Callback(hObject, eventdata, handles)
global roi_img x_s x_e
roi_cross_section = mean(roi_img);
h=hist(reshape(roi_img,1,numel(roi_img)),0:255); %reshaping the image matrix to 1 row and hist makes the values histogram (how many shows of each value in the range of 0-255)
maxpeak=find(h==max(h)); %finds the highest GL peak - the GL of most of the pixels
bkgrnd=min(maxpeak)-1; %The actual GF is -1 since the range is up to 256
axes(handles.cut_img_hist);
plot((roi_cross_section));axis([0,x_e-x_s,bkgrnd,100])
xlim([0 x_e-x_s])
function x_start_Callback(hObject, eventdata, handles)
function x_start_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function x_end_Callback(hObject, eventdata, handles)
function x_end_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function y_start_Callback(hObject, eventdata, handles)
function y_start_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function y_end_Callback(hObject, eventdata, handles)
function y_end_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function cut_Callback(hObject, eventdata, handles)
global image roi_img x_s x_e
x_s = get(handles.x_start,'String');
x_e = get(handles.x_end,'String');
y_s = get(handles.y_start,'String');
y_e = get(handles.y_end,'String');
if isempty(x_s) || isempty(x_e) || isempty(y_s) || isempty(y_e)
f = errordlg( 'Values Error' , 'Error' );
else
x_s = str2double(x_s); x_e = str2double(x_e); y_s = str2double(y_s); y_e = str2double(y_e);
roi_img=image(y_s:y_e,x_s:x_e);
axes(handles.cut_img);
imagesc(roi_img)
impixelinfo
set(handles.img_hist,'enable','on');
end
function cut_panel_CreateFcn(hObject, eventdata, handles)
Thanks for the help
Image Analyst
Image Analyst 2023-7-20
Looks like you forgot to attach the fig and m file but that's OK because I'm writing this from a computer that does not have MATLAB on it right now. Try moving cla(handles.org_img)
to the OutputFCN function because maybe the axes does not yet by the time you called in in OpeningFcn. So move it either to the end of OpeningFcn, or to the OutputFcn, or else put drawnow on the line before it in the OpeningFcn. If that doesn't work, make sure the Tag in GUIDE is 100% exactly what you have in your code, down to the capitalization.
I should be back home later tonight and might be able to try your programs then if you attach them.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by