function Untitled_5_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
[filename, pathname]=uigetfile({'*.jpg;*.tif;*.png;*.gif';'All Image Files'},'read the picture');
str=[pathname filename];
im=imread(str);
guidata(hObject,handles);
set(handles.edit1,'string',str);
axes(handles.axes1);
imshow(im);
% --------------------------------------------------------------------
function Untitled_6_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
clear all;
close(gcf);
% --------------------------------------------------------------------
function Untitled_7_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im;
global gray;
cla(handles.axes2,'reset');
axes(handles.axes2);
gray=rgb2gray(im);
imshow(gray);
% --------------------------------------------------------------------
function Untitled_8_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global gray;
global I;
I=medfilt2(gray,[3 3]);
cla(handles.axes2,'reset');
axes(handles.axes2);
imshow(I);
% --------------------------------------------------------------------
function Untitled_9_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I;
global J;
[W,H]=size(I);
for x=2:W-1
for y=2:H-1
R1=(-1)*I(x-1,y-1)+I(x+1,y-1)-2*I(x-1,y)+2*I(x+1,y)-I(x-1,y+1)+I(x+1,y+1); %%横向检测
R2=I(x-1,y-1)+2*I(x,y-1)+I(x+1,y-1)-I(x-1,y+1)-2*I(x,y+1)-I(x+1,y+1); %%纵向检测
R3=I(x,y-1)+2*I(x+1,y-1)-I(x-1,y)+I(x+1,y)-2*I(x+1,y+1)-I(x,y+1); %%45°算子检测
R4=2*I(x-1,y-1)+I(x,y-1)+I(x-1,y)-I(x+1,y)-I(x,y+1)-2*I(x+1,y+1); %%-45°算子检测
R0=[abs(R1),abs(R2),abs(R3),abs(R4)];
R=sort(R0,'descend');
switch(R(1))
case abs(R1)
J(x,y)=R1;
case abs(R2)
J(x,y)=R2;
case abs(R3)
J(x,y)=R3;
case abs(R4)
J(x,y)=R4;
end
end
end
cla(handles.axes2,'reset');
axes(handles.axes2);
imshow(J);
figure,imhist(J);