I need to change thess GUI codes to ordinary codes

1 次查看(过去 30 天)
Hello everyone
I have these 2 codes and I need a to change them to an ordinary script where input images are declared in the code itself and output is displayed on the commmand window
thank you
code 1:
function varargout = push(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @push_OpeningFcn, ...
'gui_OutputFcn', @push_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 push_OpeningFcn(hObject, eventdata, handles, varargin)
handles.pic='test1.jpg';
handles.output = hObject;
handles.pic='test1.jpg';
function varargout = push_OutputFcn(hObject, eventdata, handles)
function pushbutton1_Callback(hObject, eventdata,handles)
%function pattmatch(k,p)
display('anish');
k=handles.XX;
p=handles.YY;
[x,y,z] = size(k);
if(z==1)
;
else
k = rgb2gray(k);
end
[x,y,z] = size(p);
if(z==1)
;
else
p = rgb2gray(p);
end
edge_det_k = edge(k,'prewitt');
edge_det_p = edge(p,'prewitt');
%definition of different variables to be used in the code below
%output variable if pictures have been matched.
OUTPUT_MESSAGE = ' almost same x-ray images ';
%output variable if objects in the whole picture have not been matched.
OUTPUT_MESSAGE2 = ' x-ray images not matching ';
%initialization of different variables used
matched_data = 0;
white_points = 0;
black_points = 0;
x=0;
y=0;
l=0;
m=0;
%for loop used for detecting black and white points in the picture.
for a = 1:1:300
for b = 1:1:300
if(edge_det_k(a,b)==1)
white_points = white_points+1;
else
black_points = black_points+1;
end
end
end
display('testing');
%for loop comparing the white (edge points) in the two pictures
for i = 1:1:300
for j = 1:1:300
if(edge_det_k(i,j)==1)&(edge_det_p(i,j)==1)
matched_data = matched_data+1;
else
;
end
end
end
total_data = white_points;
total_matched_percentage = (matched_data/total_data)*100;
set(handles.result,'String',total_matched_percentage);
if(total_matched_percentage >= 85) %can add flexability at this point by reducing the amount of matching.
total_matched_percentage
OUTPUT_MESSAGE
display(OUTPUT_MESSAGE);
set(handles.result1,'String',OUTPUT_MESSAGE);
else
total_matched_percentage
OUTPUT_MESSAGE2
display(OUTPUT_MESSAGE2);
set(handles.result1,'String',OUTPUT_MESSAGE2);
end
code 2:
function varargout = Compare(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Compare_OpeningFcn, ...
'gui_OutputFcn', @Compare_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 Compare_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function varargout = Compare_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
function pushbutton2_Callback(hObject, eventdata, handles)
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.png','Select an image');
global I1;
I1 =imread(strcat(PathName,FileName));
axes(handles.axes1);
imshow(I1);
function pushbutton3_Callback(hObject, eventdata, handles)
function pushbutton4_Callback(hObject, eventdata, handles)
function pushbutton5_Callback(hObject, eventdata, handles)
function pushbutton6_Callback(hObject, eventdata, handles)
function pushbutton5_ButtonDownFcn(hObject, eventdata, handles)
[FileName,PathName] = uigetfile('*.png','Select an image');
global I2;
I2 =imread(strcat(PathName,FileName));
axes(handles.axes3);
imshow(I2);
function pushbutton6_ButtonDownFcn(hObject, eventdata, handles)
global I1;
global I2;
global I3;
global I4;
global I5;
% convert images to type double (range from from 0 to 1 instead of from 0 to 255)
Imaged1 = im2double(I1);
Imaged2 = im2double(I2);
Imaged3 = im2double(I3);
Imaged4 = im2double(I4);
Imaged5 = im2double(I5);
% reduce three channel [ RGB ] to one channel [ grayscale ]
Imageg1 = rgb2gray(Imaged1);
Imageg2 = rgb2gray(Imaged2);
Imageg3 = rgb2gray(Imaged3);
Imageg4 = rgb2gray(Imaged4);
Imageg5 = rgb2gray(Imaged5);
% Calculate the Normalized Histogram of Image 1 and Image 2
hn1 = imhist(Imageg1)./numel(Imageg1);
hn2 = imhist(Imageg2)./numel(Imageg2);
hn3 = imhist(Imageg3)./numel(Imageg3);
hn4 = imhist(Imageg4)./numel(Imageg4);
hn5 = imhist(Imageg5)./numel(Imageg5);
% Calculate the histogram error/ Difference
f1 = sum((hn1 - hn2).^2);
f2 = sum((hn1 - hn3).^2);
f3 = sum((hn1 - hn4).^2);
f4 = sum((hn1 - hn5).^2);
set(handles.text2,'String',f1)
set(handles.text3,'String',f2)
set(handles.text4,'String',f3)
set(handles.text5,'String',f4)
[FileName,PathName] = uigetfile('*.png','Select an image');
global I3;
I3 =imread(strcat(PathName,FileName));
axes(handles.axes4);
imshow(I3);
[FileName,PathName] = uigetfile('*.png','Select an image');
global I4;
I4 =imread(strcat(PathName,FileName));
axes(handles.axes5);
imshow(I4);
[FileName,PathName] = uigetfile('*.png','Select an image');
global I5;
I5 =imread(strcat(PathName,FileName));
axes(handles.axes6);
imshow(I5);

回答(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