function varargout = lesson3(varargin)
% LESSON3 M-file for lesson3.fig
% LESSON3, by itself, creates a new LESSON3 or raises the existing
% singleton*.
%
% H = LESSON3 returns the handle to a new LESSON3 or the handle to
% the existing singleton*.
%
% LESSON3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LESSON3.M with the given input arguments.
%
% LESSON3('Property','Value',...) creates a new LESSON3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before lesson3_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to lesson3_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 lesson3
% Last Modified by GUIDE v2.5 23-Apr-2013 16:30:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lesson3_OpeningFcn, ...
'gui_OutputFcn', @lesson3_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 lesson3 is made visible.
function lesson3_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output 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 lesson3 (see VARARGIN)
% Choose default command line output for lesson3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes lesson3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = lesson3_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output 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 output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile({'*.jpg';'*bmp';'*.gif'},'选择图片');
%合成图片路径+文件名
str=[pathname filename];
%读取图片
im=imread(str);
%使用第一个axes
axes(handles.axes1);
imshow(im);
handles.picture = im;
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
im = handles.picture;
axes(handles.axes2);
imshow(im);
下面是图像处理的程序 可以直接调用不 怎么调用
function H_location=xin_ulfast_OD(img_input)
img_input=imread('E:\study\tuxiang\PJ stare\im0022.jpg');
f=img_input;
R=f(:,:,1);
G=f(:,:,2);
t=35/255;
f1=im2bw(R,t);
se=strel('square',19);
f1=imerode(f1,se);
f1=double(f1);
I=G;
%I=medfilt2(I,[11 11]);
%I = smoothing(I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I=double(I);
gdt_s1=[1 0 -1];
gdt_s2=[1 0 -1]';
E_V=imfilter(I,gdt_s1);
E_H=imfilter(I,gdt_s2);
edgediff=zeros(size(G));
for i=1:size(I,1)
for j=1:size(I,2)
if I(i,j)~=0
edgediff(i,j)=(abs(E_V(i,j))-abs(E_H(i,j)))./I(i,j); %%加了绝对值
else
edgediff(i,j)=0;
end
end
end
edgediff=edgediff.*f1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
row_siz=15;
edgediff_pad=padarray(edgediff,[0 row_siz]);
[M,N]=size(I);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=(row_siz+1):(N+row_siz)
block_diff=edgediff_pad(:,j-row_siz:j+row_siz);
F_HRZ=sum(sum(block_diff));
H_projection(j-row_siz)=F_HRZ;
end
H_projection=H_projection/max(H_projection(:));
H_location=find(H_projection==max(H_projection));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
club=ones(101,101);
edgesum=(abs(E_V)+abs(E_H)).*I;
edgesum=edgesum.*f1;
G_ver=imfilter(edgesum,club);
G_ver=G_ver(:,H_location);
V_location=find(G_ver==max(G_ver));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%figure,imshow(edgediff);
%figure,imshow(edgesum,[]);
%figure,plot(1:N,H_projection(1:N));
%figure,plot(1:M, G_ver(1:M));
figure,imshow(G);
hold on
plot(H_location,V_location,'gX','MarkerSize',20','LineWidth',3);
hold off
%figure,plot(1:M, G_ver(1:M));