function detect_iris(id)

im = imread(sprintf('../../aligned_data/martin/%s.jpg', id));
im = double(im(390:500, 500:700, :))/255;
im = rgb2gray(im);

threc = 0.15;
l_threc = 18;
margin = 5;

im_x = imfilter(im, [-1 0 1]);
im_x = im_x(:, margin:end-margin);
im   = im (:, margin:end-margin);

line = abs(im_x) > threc;


L = bwlabel(line, 4);

l  = [1 : max(L(:))];
ll = label_length(L);
lx = label_center(L);

lc = l(ll>l_threc); 
lcx = lx(lc);

[~ , idx]= sort(lcx);

line_1 = L==lc(idx(end));
line_2 = L==lc(idx(1));


iris_contour = line_1 + line_2;
[x y]=label2xy(iris_contour,1);

[xc yc R] = circle_fit(x , y);

xc=ceil(xc); 
yc=ceil(yc);
R = ceil(R);


figure;imshow(o);


im(yc-R:yc+R,xc)=0;
im(yc:yc,xc-R:xc+R)=0;

figure;imshow([ im 2*abs(im_x) ;  line iris_contour]);


function [x y] = label2xy(bwlabel,n);
  [h w]=size(bwlabel);
  [xx yy]=meshgrid(1:w, 1:h);
  x = xx(bwlabel==n);
  y = yy(bwlabel==n);
  

function nel = label_length(bwlabel)
  nel = zeros(max(bwlabel(:)),1);
  [h w]=size(bwlabel);
  [xx yy]=meshgrid(1:w, 1:h);
  for i = 1 : max(bwlabel(:))
    
    ys = yy(bwlabel==i);
    nel(i) = max(ys(:))- min(ys(:));
  end
 
function nel = label_center(bwlabel)
  nel = zeros(max(bwlabel(:)),1);
  [h w]=size(bwlabel);
  [xx yy]=meshgrid(1:w, 1:h);
  for i = 1 : max(bwlabel(:))
    
    xs = xx(bwlabel==i);
    nel(i) = mean(xs);
  end
   
function [xc yc R] = circle_fit(x,y)
  x=x(:); y=y(:);
  a=[x y ones(size(x))]\[-(x.^2+y.^2)];
  xc = -.5*a(1);
  yc = -.5*a(2);
  R  =  sqrt((a(1)^2+a(2)^2)/4-a(3));
