1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| clear all
close all
clc
%%image transformer en binaire%%
Iris=imread('IrisSeekk.bmp');
I=rgb2gray(Iris);
if nargin == 1
t = t_autoset(I);
end
sz=size(I);
BW=repmat(logical(uint8(0)),sz(1),sz(2));
for r = 3 : sz(1)-2
for c = 3 : sz(2)-2
if I(r,c)<t
if (I(r-1,c-1)<t)&(I(r-1,c)<t)&(I(r-1,c+1)<t)&(I(r,c-1)<t)&(I(r,c+1)<t)&(I(r+1,c-1)<t)&(I(r+1,c)<t)&(I(r+1,c+1)<t)
BW(r,c) = 0;
else
BW(r,c) = 1;
end
else
BW(r,c) = 0;
end
end
end
for r = 1 : sz(1)
BW(r,1:2) = 0;
BW(r,(size(BW,2)-1):size(BW,2)) = 0;
end
for c = 1 : sz(2)
BW(1:2,c) = 0;
BW((size(BW,1)-1):size(BW,1),c) = 0;
end
figure,imshow(I)
figure,imshow(BW)
%%Transformer de hough%%
Ibinary = BW;
Rp=[10,200];
[sy,sx]=size(Ibinary);
[y,x]=find(Ibinary);
totalpix = length(x);
HM_tmp = zeros(sy*sx,1);
b = 1:sy;
a = zeros(sy,totalpix);
if nargin == 1
R_min = 1;
R_max = max(max(x),max(y));
else
R_min = Rp(1);
R_max = Rp(2);
end
y = repmat(y',[sy,1]);
x = repmat(x',[sy,1]);
HPN = 0;
for R = R_min : R_max
R2 = R^2;
b1 = repmat(b',[1,totalpix]);
b2 = b1;
a1 = (round(x - sqrt(R2 - (y - b1).^2)));
a2 = (round(x + sqrt(R2 - (y - b2).^2)));
b1 = b1(imag(a1)==0 & a1>0 & a1<sx);
a1 = a1(imag(a1)==0 & a1>0 & a1<sx);
b2 = b2(imag(a2)==0 & a2>0 & a2<sx);
a2 = a2(imag(a2)==0 & a2>0 & a2<sx);
ind1 = sub2ind([sy,sx],b1,a1);
ind2 = sub2ind([sy,sx],b2,a2);
ind = [ind1; ind2];
val = ones(length(ind),1);
data=accumarray(ind,val);
HM_tmp(1:length(data)) = data;
HM2_tmp = reshape(HM_tmp,[sy,sx]);
maxval = max(max(HM2_tmp));
if maxval>HPN
HPN = maxval;
HM = HM2_tmp;
Rc = R;
end
end
[B,A] = find(HM==HPN);
C = [mean(A),mean(B),Rc];
xc=C(1);
yc=C(2);
radius=C(3); |
Partager