segment_print.m
Upload User: hswx021
Upload Date: 2014-02-10
Package Size: 3k
Code Size: 3k
Category:

Graph Recognize

Development Platform:

Matlab

  1. %--------------------------------------------------------------------------
  2. %  Version 1.0 March 2005
  3. %  Copyright (c) 2005-2010 by Center for Unified Biometrics and Sensors
  4. %  www.cubs.buffalo.edu
  5. %
  6. %segment_print
  7. %segments the fingerprint region from the background based on morphological
  8. %operations
  9. %syntax:
  10. % [msk]= segment_print(img,iters,verbose)
  11. % img       - original image 
  12. % verbose   - a value of 1 displays intermediate results
  13. %Contact:
  14. %   ssc5@cubs.buffalo.edu, sharat@mit.edu
  15. %   http://www.sharat.org
  16. %--------------------------------------------------------------------------
  17. function msk    =   segment_print(img,verbose)
  18.     [ht,wt]     =   size(img);
  19.     y           =   im2double(img);
  20.     img         =   im2double(img);
  21.     ITERS       =   4;
  22.     %-----------------
  23.     %compute the mask
  24.     %-----------------
  25.     for i=1:ITERS
  26.         y           =   imerode(y,ones(5,5));      %diffuse blob
  27.         c           =   y.^2;                       %enhance contrast
  28.         msk         =   ~im2bw(c,otsu_threshold(c)); %find mask
  29.         %---------------------------------------------------
  30.         %remove sections that might grow to join main blob
  31.         %---------------------------------------------------
  32.         if(i == 2)
  33.             small       =   msk & ~bwareaopen(msk,floor(0.1*ht*wt),4);
  34.             y(small==1) =   sum(sum(img))/(ht*wt);
  35.         end;
  36.         %---------------------------------------------------
  37.         %display intermediate result
  38.         %---------------------------------------------------
  39.         if(verbose==1)
  40.             %subplot(1,4,1),imagesc(img),title('Original');
  41.             %subplot(1,4,2),imagesc(y),title('Eroded');
  42.             %subplot(1,4,3),imagesc(c);colormap('gray'),title('Enhanced');
  43.             %subplot(1,4,4),imagesc(msk),title('Segmented');
  44.             figure(1);imshow(img),title('Original');
  45.             figure(2);imshow(y),title('Eroded');
  46.             figure(3);imshow(c);colormap('gray'),title('Enhanced');
  47.             figure(4);imshow(msk),title('Segmented');
  48.             pause;
  49.             drawnow;
  50.         end;
  51.     end;
  52.     %----------------------------------------
  53.     %get the largest blob as the fingerprint
  54.     %----------------------------------------
  55.     msk = bwareaopen(msk,round(0.15*ht*wt));
  56.     msk = imerode(msk,ones(7,7));           %erode boundary
  57.     msk = imfill(msk,'holes');              %fill holes
  58.     %---------------------------------------------------
  59.     %display final result
  60.     %---------------------------------------------------
  61.     if(verbose==1)
  62.         figure,imagesc(msk.*img),axis image,colormap('gray'),title('Final');
  63.     end;
  64. %end function isotropic_diffusion