Hello,
I am new in GUI. I have created some GUI script in order to process images that contains the following syntax:
function Num_seg_Callback(hObject, eventdata, handles)
numseg=str2double(get(hObject,'String'));
if isempty(numseg) %I have also tried isnan
numseg=1;
end
handles.numseg=numseg;
guidata(hObject,handles);
I would like to set 1 as the default value of a text edit object (numseg) which I use below in my code. This syntax is giving an error (Reference to non-existent field 'numseg') and it works only if I first write a number and then delete it. Does anyone have an idea of why is this occurring? Why it doesn't work the first time I run it?
I have also tried: if isnan(numseg) set (handles.numseg,'String',1); end ...

댓글 수: 3

Rik
Rik 2018년 7월 23일
Is specifically this function itself returning an error? Or did you forget to initialize the numseg field?
I Rik
Thanks for your response,
I think that it triggers the error when I try to call numseg in this code below:
%====================================================================================
% BOTON SEGMENTACION
%====================================================================================
% --- Executes on button press in Boton_segmentar.
function Boton_segmentar_Callback(hObject, eventdata, handles)
% hObject handle to Boton_segmentar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%SI EXISTE LA IMAGEN CORTADA, LA SEGMENTAS Y SI NO HA CORTADO NADA LO HACES
%CON LA CRUDA:
%------------------------------------------------------------------------------
% PREPROCESAMOS LA IMAGEN PARA SEGMENTAR
%------------------------------------------------------------------------------
Imagengs=rgb2gray(Imagen_segmentar);
histeq=adapthisteq(Imagengs); %Ecualizacion del histograma
ajus = imadjust(histeq,[0.3 0.7],[0 1]); %Ajustamos contraste
edges= edge(ajus,'Canny'); %Calculamos los bordes
fil=imdilate(edges,ones(7,7)); %Dilatamos los puntos
fil=imcomplement(fil); %Creamos la complementaria
%-----------------------------------------------------------------------------
% SEGMENTACION
%-----------------------------------------------------------------------------
lab=bwlabel(fil); %Marcamos las etiquetas de las regiones
BW2 = bwareafilt(fil,handles.numseg); %Eliminamos todos los segmentos que no sean del strip
BW2_fill=imfill(BW2,'holes'); %Rellenamos los huecos que puedan quedar en medio del strip
strip=bwlabel(BW2_fill); %Volvemos a guardar las etiquetas de los nuevos segmentos
%-------------------------------------------------------------------
%MOSTRAMOS EL RESULTADO DE LA SEGMENTACION
%--------------------------------------------------------------------
axes(handles.plot1) %Le indicamos que estamos trabajando en el plot1
cla %Borra la imagen anterior que haya en el current axes
overlay2 = imOverlay(Imagen_segmentar, BW2_fill, [.3 1 .3]);
imshow(overlay2); %Muestra la imagen segmentada
MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ 2018년 7월 23일
I don't know what do you mean with initialize the field... Sorry

댓글을 달려면 로그인하십시오.

 채택된 답변

Rik
Rik 2018년 7월 23일

1 개 추천

In your OpeningFcn, you need to set a value for the numseg field. That way, the field exists in your handles struct and that other function can use it.

댓글 수: 1

MARIA RODRIGUEZ SANZ
MARIA RODRIGUEZ SANZ 2018년 7월 23일
Thank you. That worked perfect! So simply! No if statements were necessary...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2018a

태그

질문:

2018년 7월 23일

댓글:

2018년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by