How to work with GUI data , perform functions and see output in workspace?

조회 수: 1 (최근 30일)
Hello,
I would really appreciate if I can have some help. I have designed a GUI for my digital image processing project. I am struggling to get this handles and passing of arguments right. I load image from my file, then I have other push buttons, like filtering and thresholding. SO the goal is to paste my function under the specific callback and when GUI runs, the operator would click on filtername and then my code will execute and show output. I have tried few things, but the problem is I can't pass between function everything correctly. And when I use imfindcircle for detecting my optic disk in image, the [i j] index is a problem, and I can't evaluate what is wrong because there is no data in workspace to see.
Here is my code. How do I call the output image to next function so that it can perform ANOTHER operation on it. I tried setappdata and getappdata....
function Main_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject; guidata(hObject, handles); set(gcf,'Position',get(0,'Screensize'));
% Retrieve default image and display it
Foto = 'C:\Users\nvg\Desktop\Hoofstuk 3\Matlab\images'; % default image
BeeldBestaan = exist(Foto,'file'); % test for existence of filenames
if (BeeldBestaan == 2) % if default image is found
OriginalRGB = imread(Foto); % read default image else OriginalRGB = zeros(1300,1500,3);
end
imshow(OriginalRGB,'parent',handles.OriginalImage); handles.OriginalRGB = OriginalRGB; % storage of main image in handles
% Update handles structure
guidata(hObject, handles);
function varargout = Main_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in Load.
function Load_Callback(hObject, eventdata, handles)
FilterSpec = {'*.png'};
DefaultName = 'C:\Users\nvg\Desktop\Hoofstuk 3\Matlab\images';
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec,'Image file selector',DefaultName);
if (FilterIndex >0)
LeerNaam = strcat(PathName,FileName); % get filename
OriginalRGB = imread(LeerNaam); % read image
imshow(OriginalRGB,'parent',handles.OriginalImage); % display image
handles.OriginalRGB = OriginalRGB;
guidata(hObject, handles); % update handles
end
handles.OriginalRGB = OriginalRGB; guidata(hObject, handles);
setappdata(handles.Load,'image',OriginalRGB);
% --- Executes during object creation, after setting all properties.
function Main_CreateFcn(hObject, eventdata, handles)
% --- Executes on button press in Optic_disk.
function Optic_disk_Callback(hObject, eventdata, handles)
OriginalRGB = getappdata(handles.Load,'image');
handles.OriginalRGB = OriginalRGB;
guidata(hObject, handles);
red=OriginalRGB(:,:,1);
figure, imshow(red), title 'red channel of RGB image';
[centers, radii] = imfindcircles(red,[50 140],'Sensitivity',0.94, 'EdgeThreshold', 0.03);
% h= viscircles(centers,radii, 'EdgeColor','r');
[i j]=find(radii==max(radii(:)));
radii = getappdata(FindCirclesFig,'radii');
middelpunt=centers(i,:)
r=max(radii)+80;
xa=middelpunt(1);
ya=middelpunt(2);
th = 0:pi/50:2*pi;
xunit = r * cos(th) + xa;
yunit = r * sin(th) + ya;
figure, imshow(RGB);
hold on
sirkel_plot = plot(xunit, yunit);
hold off
Create a logical image of a circle with specified diameter, center, and image size.
imageSizeX = size(red,1);
imageSizeY =size(red,2);
[columnsInImage rowsInImage] = meshgrid(1:imageSizeY,1:imageSizeX);
% Next create the circle in the image.
centerX =xa;
centerY =ya;
radius = r;
circlePixels = (rowsInImage - centerY).^2 + (columnsInImage - centerX).^2 <= (radius.^2);
%optic disk inverted
Optic_disk = imcomplement(circlePixels);

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 28일
편집: Azzi Abdelmalek 2013년 9월 28일
When you use variables x,y and z in one function and want to pass them to another function. At the end of your function add
handles.x=x;
handles.y=y;
handles.z=z;
guidata(hObject,handles)
If you want to use x in another function, add at the beginning of your function
x=handles.x
and do not forget to update guidata if the value of x changes
guidata(hObject,handles)

추가 답변 (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