Sunteți pe pagina 1din 7

function varargout = ur3(varargin) % UR3 M-file for ur3.

fig % UR3, by itself, creates a new UR3 or raises the existing % singleton*. % % H = UR3 returns the handle to a new UR3 or the handle to % the existing singleton*. % % UR3('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in UR3.M with the given input arguments. % % UR3('Property','Value',...) creates a new UR3 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before ur3_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to ur3_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help ur3 % Last Modified by GUIDE v2.5 05-May-2012 23:56:22 % Begin initialization code - DO NOT EDIT global j; global q; q='000'; gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ur3_OpeningFcn, ... 'gui_OutputFcn', @ur3_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 % End initialization code - DO NOT EDIT % --- Executes just before ur3 is made visible. function ur3_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no text1 args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to ur3 (see VARARGIN) % Choose default command line text1 for ur3 handles.text1 = hObject;

% Update handles structure guidata(hObject, handles); % UIWAIT makes ur3 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = ur3_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning text1 args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line text1 from handles structure varargout{1} = handles.text1; % --- Executes on button press in Browse. function Browse_Callback(hObject, eventdata, handles) % get a file to read [FileName, FilePath] = uigetfile({ '*.jpg'; '*.jpeg'; '*.bmp'; '*.gif'; '*.tiff' ; '*.png' }, 'Select an Image...'); % read the image I = imread([FilePath, FileName]); % set the file name and path to the edit box as well set(handles.editFilePath, 'String', [FilePath, FileName]); % set the image in the user data, if this is not done, the image would be % lost setappdata(ur3, 'MyImage', I); % set the file name and path in the user data setappdata(ur3, 'FileNameAndPath', [FilePath, FileName]); % hObject handle to Browse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in ShowImage. function ShowImage_Callback(hObject, eventdata, handles) Image = getappdata(ur3, 'MyImage'); % figure, imshow(Image); handles.current_data=Image; axes(handles.axes2); imshow(handles.current_data); guidata(hObject, handles); % hObject handle to ShowImage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

function editFilePath_Callback(hObject, eventdata, handles) FilePath = get(handles.editFilePath, 'String'); set(handles.editFilePath, 'String', FilePath); I = imread(FilePath); setappdata(ur3, 'MyImage', I); setappdata(ur3, 'FileNameAndPath', FilePath);

% hObject handle to editFilePath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of editFilePath as text % str2double(get(hObject,'String')) returns contents of editFilePath as a double % --- Executes during object creation, after setting all statomoments. function editFilePath_CreateFcn(hObject, eventdata, handles) % hObject handle to editFilePath (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgr oundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all statomoments. function Browse_CreateFcn(hObject, eventdata, handles) % hObject handle to Browse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object deletion, before destroying statomoments. function Browse_DeleteFcn(hObject, eventdata, handles) % hObject handle to Browse (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % % % % % % % % % % % % % % % % % % % % % % --- Executes on button press in properties. function properties_Callback(hObject, eventdata, handles) %clc; %close all; FilePath = get(handles.editFilePath, 'String'); set(handles.editFilePath, 'String', FilePath); I = imread(FilePath); %z=rgb2gray(I); %imshow(z); p=imhist(I); m=statomoments(p,4); y1=mybinary(m(1)); y2=mybinary(m(2)); y3=mybinary(m(3)); y4=mybinary(m(4)); j=horzcat(y1,y2,y3,y4,q); %disp(j); str=sprintf('output : %s',j); set(handles.edit4,'String',str); hObject handle to properties (see GCBO) eventdata reserved - to be defined in a future version of MATLAB handles structure with handles and user data (see GUIDATA)

function edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgr oundColor')) set(hObject,'BackgroundColor','white'); end function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.current_data1=rgb2gray(handles.current_data); z_1=edge(handles.current_data1,'sobel'); axes(handles.axes4); imshow(z_1); guidata(hObject, handles); % Hint: get(hObject,'Value') returns toggle state of radiobutton5

% --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) a=handles.current_data; RGB = a; HSI = rgb2hsv(RGB); H = HSI(:,:,1); S = HSI(:,:,2); I = HSI(:,:,3); [row, col, layer] = size(RGB); edge = EdgeDetection(RGB); fImage = zeros(row, col); rgb = a; [hLow, hHigh] = Hue(rgb, 0.03); [sLow, sHigh] = Saturation(rgb, 0.1); [iLow, iHigh] = Intensity(rgb, 0.1); tempImage = Segment(RGB, hLow, hHigh, sLow, sHigh, iLow, iHigh); for i=1:row for j=1:col if tempImage(i,j)>0 fImage(i,j) = tempImage(i,j); end

end end rgb = a; [hLow, hHigh] = Hue(rgb, 0.02+0.1); [sLow, sHigh] = Saturation(rgb, 0.2+0.1); [iLow, iHigh] = Intensity(rgb, 0.1+0.1); tempImage = Segment(RGB, hLow, hHigh, sLow, sHigh, iLow, iHigh); for i=1:row for j=1:col if tempImage(i,j)>0 fImage(i,j) = tempImage(i,j); end end end rgb = a; [hLow, hHigh] = Hue(rgb, 0.02+0.1); [sLow, sHigh] = Saturation(rgb, 0.2+0.1); [iLow, iHigh] = Intensity(rgb, 0.1+0.1); tempImage = Segment(RGB, hLow, hHigh, sLow, sHigh, iLow, iHigh); for i=1:row for j=1:col if tempImage(i,j)>0 fImage(i,j) = tempImage(i,j); end end end rgb = a; [hLow, hHigh] = Hue(rgb, 0.05+0.1); [sLow, sHigh] = Saturation(rgb, 0.2+0.1); [iLow, iHigh] = Intensity(rgb, 0.1+0.1); tempImage = Segment(RGB, hLow, hHigh, sLow, sHigh, iLow, iHigh); for i=1:row for j=1:col if tempImage(i,j)>0 fImage(i,j) = tempImage(i,j); end end end combine = Combine(RGB, fImage, edge); sImage = zeros(row, col, layer); for i=1:row for j=1:col for k=1:layer if combine(i,j)==1 sImage(i,j,1) = H(i,j); sImage(i,j,2) = S(i,j); sImage(i,j,3) = I(i,j); end end end end sRGB = hsv2rgb(sImage); block=ones(5,5); d=imdilate(edge,block); for i=1:2 d = imdilate(d,block); end d = imfill(d,'holes'); finalImage21 = zeros(row,col,layer);

for i=1:row for j=1:col if d(i,j)>0 finalImage21(i,j,1) = H(i,j); finalImage21(i,j,2) = S(i,j); finalImage21(i,j,3) = I(i,j); end end end sRGB = hsv2rgb(sImage); finalImage21RGB1 = hsv2rgb(finalImage21); a=finalImage21RGB1; axes(handles.axes3); imshow(a); guidata(hObject, handles); % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton6.

% --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) a=imread('1.jpg'); b=rgb2gray(a); z_1=edge(handles.current_data1,'sobel'); z_2=edge(b,'sobel'); distance=modhausdorffdist(z_1,z_2); dis=abs(distance); % str1=sprintf('%d',distance); % set(handles.text1,str1); str=sprintf('output : %d',dis); set(handles.edit5,'String',str); axes(handles.axes5); imshow(a); guidata(hObject, handles); % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

function edit5_Callback(hObject, eventdata, handles) % hObject handle to edit5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit5 as text % str2double(get(hObject,'String')) returns contents of edit5 as a double % --- Executes during object creation, after setting all properties. function edit5_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgr oundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all properties. function pushbutton5_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function ShowImage_CreateFcn(hObject, eventdata, handles) % hObject handle to ShowImage (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

S-ar putea să vă placă și