www.pudn.com > eyedemo.rar > eyedemo.asv
%为方便使用,再次将预处理过程的各步骤集中于一个界面中实现
%本软件使用说明
%(1)由于运行时需要调用本目录下以及Segmentation下的函数,所以请在matlab软件中的add path里添加本程序所在目录以及其子目录。
%(2)先将需要处理的图像转化为JPG图像,加入eyedemo.m所在目录中,命名为菜单中所提供001-008共8幅JPG图像。()
%(3)选定图像,之后选定操作方式。若直接选择归一化,则也需运行分割运算,只是输出归一化结果;同理,运行图像增强也将运行前两步运算,故所需时间都不会很短。
%(4)点击Info查看说明。
%(5)点击close关闭界面退出本函数。
%
%
%
function eyedemo(action, varargin)
if nargin<1,
action='InitializeEYEDEMO';
end;
feval(action,varargin{:});
return;
%初始化EYEDEMO
function InitializeEYEDEMO()
% 如果已有一个程序运行,将其提到前面
h = findobj(allchild(0), 'tag', 'iris Detection Demo');
if ~isempty(h)
figure(h(1))
return
end
screenD = get(0, 'ScreenDepth');
if screenD>8
grayres=256;
else
grayres=128;
end
EyeDemoFig = figure( ...
'Name','iris Detection Demo', ...
'NumberTitle','off', 'HandleVisibility', 'on', ...
'tag', 'iris Detection Demo', ...
'Visible','off', 'Resize', 'off',...
'BusyAction','Queue','Interruptible','off', ...
'Color', [.8 .8 .8], ...
'IntegerHandle', 'off', ...
'DoubleBuffer', 'on');
figpos = get(EyeDemoFig, 'position');
% 调整图像大小
figpos(3:4) = [560 420];
horizDecorations = 10;
vertDecorations = 45;
screenSize = get(0,'ScreenSize');
if (screenSize(3) <= 1)
screenSize(3:4) = [100000 100000];
end
if (((figpos(3) + horizDecorations) > screenSize(3)) | ...
((figpos(4) + vertDecorations) > screenSize(4)))
delete(EyeDemoFig);
error(['Screen resolution is too low ', ...
'(or text fonts are too big) to run this demo']);
end
dx = screenSize(3) - figpos(1) - figpos(3) - horizDecorations;
dy = screenSize(4) - figpos(2) - figpos(4) - vertDecorations;
if (dx < 0)
figpos(1) = max(5,figpos(1) + dx);
end
if (dy < 0)
figpos(2) = max(5,figpos(2) + dy);
end
set(EyeDemoFig, 'position', figpos);
rows = figpos(4); cols = figpos(3);
hs = (cols-512) / 3; %水平间距
bot = rows-2*hs-256; % 图像的底部位置
%====================================
% 所有按钮和菜单的参数
ifs = hs/2; % Intraframe Spacing
Std.Interruptible = 'off';
Std.BusyAction = 'queue';
%================================
% 源图像的坐标轴
hdl.ImageAxes = axes(Std, ...
'Units', 'Pixels', ...
'Parent',EyeDemoFig,...
'ydir', 'reverse', ...
'XLim', [.5 256.5], ...
'YLim', [.5 256.5],...
'CLim', [0 255], ...
'Position',[hs bot 256 256], ...
'XTick',[],'YTick',[]);
set(get(hdl.ImageAxes, 'title'), 'string', 'Original Image');
%================================
% 边缘图像坐标轴
hdl.EdgeAxes = axes(Std, ...
'Units', 'Pixels', ...
'Parent',EyeDemoFig,...
'ydir', 'reverse', ...
'XLim', [.5 256.5], ...
'YLim', [.5 256.5],...
'CLim', [0 1], ...
'Position',[cols-hs-256 bot 256 256], ...
'XTick',[],'YTick',[]);
set(get(hdl.EdgeAxes, 'title'), 'string', 'Edge Map');
%================================
% 源图像
hdl.Image = image(Std, ...
'CData', [], ...
'CDataMapping', 'scaled', ...
'Parent',hdl.ImageAxes,...
'Xdata', [1 256],...
'Ydata', [1 256],...
'EraseMode', 'none');
%================================
% 边缘图像
hdl.Edge = image(Std, ...
'CData', [], ...
'CDataMapping', 'scaled', ...
'Parent',hdl.EdgeAxes,...
'Xdata', [1 256],...
'Ydata', [1 256],...
'EraseMode', 'none');
% 框架的背景色
bgcolor = [0.45 0.45 0.45];
fgcolor = [1 1 1]; % For text
%================================
% 图像与处理方法的选择菜单栏
mfleft=hs;
mfbot=hs;
mfwid=(3*cols/8)-1.5*hs; % 2*cols/7
mfht=bot-2*hs;
hdl.MenuFrame = uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style', 'frame', ...
'Units', 'pixels', ...
'Position', [mfleft mfbot mfwid mfht], ...
'BackgroundColor', bgcolor);
%====================================
% 提取图像的菜单 ip-> Image Popup
ipwid = mfwid-2*ifs;
ipht = 21; % (mfht-5*ifs)/3;
ipleft = mfleft+ifs;
ipbot = mfbot+1.7*ifs + 2*ipht;
hdl.ImgPop=uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style','popupmenu', ...
'Units','pixels', ...
'Position',[ipleft ipbot ipwid ipht], ...
'Enable','on', ...
'String','001|002|003|004|005|006|007|008', ...
'Tag','ImagesPop',...
'Callback','eyedemo(''LoadNewImage'')');
%图像菜单的文本标签
uicontrol( Std, ...
'Parent', EyeDemoFig, ...
'Style','text', ...
'Units','pixels', ...
'Position',[ipleft ipbot+ipht ipwid 18], ...
'Horiz','left', ...
'Background',bgcolor, ...
'Foreground',fgcolor, ...
'String','Select an Image:');
%====================================
% 方法菜单: mp-> Method Popup
hdl.Method = 'Sobel';
mpwid = ipwid;
mpht = ipht;
mpleft = ipleft;
mpbot = mfbot+1.2*ifs;
hdl.MethodPop=uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style','popupmenu', ...
'Units','pixels', ...
'Position',[mpleft mpbot mpwid mpht], ...
'Enable','on', ...
'String','segment|normalize|enhance', ...
'Tag','MethodPop',...
'Callback','eyedemo(''SelectMethod'')');
% 方法菜单的文本标签
uicontrol( Std, ...
'Parent', EyeDemoFig, ...
'Style','text', ...
'Units','pixels', ...
'Position',[mpleft mpbot+mpht mpwid 18], ...
'Horiz','left', ...
'Background',bgcolor, ...
'Foreground',fgcolor, ...
'String','opreate:');
%================================
%参数栏
pfleft =(3*cols/8)+0.5*hs; % 2*cols/7
pfbot = 1.5*hs;
pfwid =(3*cols/8)-hs; % 3*cols/7
pfht = bot-2.5*hs;
hdl.ParamFrame = uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style', 'frame', ...
'Units', 'pixels', ...
'Position', [ pfleft pfbot pfwid pfht ], ...
'BackgroundColor', bgcolor);
%====================================
%状态栏
colr = get(EyeDemoFig,'Color');
hdl.Status = uicontrol( Std, ...
'Parent', EyeDemoFig, ...
'Style','text', ...
'Units','pixels', ...
'Background', colr, ...
'Foreground', [.8 0 0], ...
'Position',[pfleft 2 pfwid 18], ...
'Horiz','center', ...
'Tag', 'Status', ...
'String','Initializing iris Detection Demo...');
%================================
%按钮栏- Apply, Info与 Close 按钮
bfleft = (3*cols/4)+.5*hs; % 5*cols/7
bfbot = hs;
bfwid = (cols/4)-1.5*hs; % 2*cols/7
bfht = bot-2*hs;
hdl.ButtonFrame = uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style', 'frame', ...
'Units', 'pixels', ...
'Position', [ bfleft bfbot bfwid bfht ], ...
'BackgroundColor', bgcolor);
%====================================
% APPLY 按钮
btnwid = bfwid - 2*ifs;
btnht = (bfht-4*ifs)/3; % 21
btnleft = bfleft + ifs;
btnbot = bfbot + bfht - ifs - btnht;
hdl.Apply=uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style','pushbutton', ...
'Units','pixels', ...
'Position',[btnleft btnbot btnwid btnht], ...
'Enable','off', ...
'String','Apply', ...
'Callback','eyedemo(''ComputeEdgeMap'')');
%====================================
% INFO 按钮
btnbot = bfbot + bfht - 2*ifs - 2*btnht;
hdl.Help=uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style','pushbutton', ...
'Units','pixels', ...
'Position',[btnleft btnbot btnwid btnht], ...
'Enable','off', ...
'String','Info', ...
'Callback','helpwin eyedemo');
%====================================
% CLOSE 按钮
btnbot = bfbot + ifs;
hdl.Close=uicontrol(Std, ...
'Parent', EyeDemoFig, ...
'Style','pushbutton', ...
'Units','pixels', ...
'Position',[btnleft btnbot btnwid btnht], ...
'Enable','off', ...
'String','Close', ...
'Callback','close(gcbf)');
set(EyeDemoFig, 'Userdata', hdl, 'Visible', 'on');
drawnow
LoadNewImage(EyeDemoFig);
drawnow
set(EyeDemoFig, 'HandleVisibility', 'Callback');
set([hdl.Apply hdl.Help hdl.Close] , 'Enable', 'on');
return
%%%
%%% 子函数 - ComputeEdgeMap
%%%
function ComputeEdgeMap(DemoFig)
if nargin<1
callb = 1; % 函数回调中
DemoFig = gcbf;
else
callb = 0; % 初始化中。。。。
end
set(DemoFig,'Pointer','watch');
setstatus(DemoFig, 'Computing the edge map...');
hdl=get(DemoFig,'Userdata');
img = getimage(hdl.Image);
global DIAGPATH
DIAGPATH = 'diagnostics';
eyeimage=rgb2gray(img);
[circleiris circlepupil imagewithnoise] = segmentiris(eyeimage);
radial_res = 20;
angular_res = 240;
%归一化
[polar_array noise_array] = normaliseiris(imagewithnoise, circleiris(2),...
circleiris(1), circleiris(3), circlepupil(2), circlepupil(1), circlepupil(3),eyeimage, radial_res, angular_res);
switch hdl.Method
case 'segment'
imagewithnoise2 = uint8(imagewithnoise);
imagewithcircles = uint8(eyeimage);
%得到虹膜外圆上点的坐标
[x,y] = circlecoords([circleiris(2),circleiris(1)],circleiris(3),size(eyeimage));
ind2 = sub2ind(size(eyeimage),double(y),double(x));
%得到瞳孔外圆上点的坐标
[xp,yp] = circlecoords([circlepupil(2),circlepupil(1)],circlepupil(3),size(eyeimage));
ind1 = sub2ind(size(eyeimage),double(yp),double(xp));
% 写噪声区域
imagewithnoise2(ind2) = 255;
imagewithnoise2(ind1) = 255;
% 覆盖圆圈
imagewithcircles(ind2) = 255;
imagewithcircles(ind1) = 255;
%w = cd;
%cd(DIAGPATH);
%cd(w);
set(hdl.EdgeAxes,'userdata',imagewithcircles)
imshow(imagewithcircles)
set(hdl.Apply, 'Enable', 'off');
case 'normalize'
set(hdl.EdgeAxes,'userdata',polar_array)
imshow(polar_array)
set(hdl.Apply, 'Enable', 'off');
set(DemoFig,'Pointer','arrow');
case 'enhance'
h=histeq(polar_array) ;
set(hdl.EdgeAxes,'userdata',h)
imshow(h)
otherwise
error('EDGEDEMO: Invalid edge detection method.');
end
%%% 子函数- SelectMethod
function SelectMethod
DemoFig = gcbf;
hdl = get(DemoFig, 'userdata');
v = get(hdl.MethodPop,{'value','String'});
hdl.Method = deblank(v{2}(v{1},:));
switch hdl.Method
case 'segment'
ActivateSPRControls(DemoFig);
case 'normalize'
ActivateLOGControls(DemoFig);
case 'enhance'
ActivateEnControls(DemoFig);
otherwise
error('EDGEDEMO: invalid method specifier.');
end
set(hdl.Apply, 'Enable', 'on');
set(DemoFig, 'userdata', hdl);
setstatus(DemoFig, ['Press ''Apply'' to compute edges.']);
%%%
%%% 子函数- LoadNewImage
%%%
function LoadNewImage(DemoFig)
if nargin<1
callb = 1; % 函数调用中
DemoFig = gcbf;
else
callb = 0; % 初始化中
end
set(DemoFig,'Pointer','watch');
hdl=get(DemoFig,'Userdata');
v = get(hdl.ImgPop,{'value','String'});
name = deblank(v{2}(v{1},:));
setstatus(DemoFig, ['Loading the ' name ' image...']);
drawnow
switch name
case '001',
a = [];
img = imread('001.jpg');
case '002',
b = [];
img = imread('002.jpg');
case '003',
c = [];
img = imread('003.jpg');
case '004',
d = [];
img = imread('004.jpg');
case '005',
e = [];
img = imread('005.jpg');
case '006',
f = [];
img = imread('006.jpg');
case '007',
g = [];
img = imread('007.jpg');
case '008',
h = [];
img = imread('008.jpg');
otherwise
error('EDGEDEMO: Unknown Image Option!');
end
set(hdl.Image, 'Cdata', img);
set(get(hdl.ImageAxes,'title'),'string',['Original ' name ' Image']);
set(DemoFig,'Pointer','arrow');
if callb
set(hdl.Apply, 'Enable', 'on');
end
drawnow
%%% 子函数 - ActivateSPRControls
function ActivateSPRControls(DemoFig)
hdl = get(DemoFig, 'UserData');
%%% 子函数 - ActivateLOGControls
function ActivateLOGControls(DemoFig)
hdl = get(DemoFig, 'UserData');
%% 子函数 ActivateEnControls(DemoFig);
function ActivateEnControls(DemoFig)
hdl=get(DemoFig,'UserData');