Home > SuperSegger > segmentation > watershedNoise.m

watershedNoise

PURPOSE ^

watershedNoise : uses watershed on an image and adds noise

SYNOPSIS ^

function [ws,num] = watershedNoise( im, minStep )

DESCRIPTION ^

 watershedNoise : uses watershed on an image and adds noise

 INPUT :
       im : input image.
       minStep : thershold value.
 OUTPUT :
       ws : black and white watershed image
       num : max value in ws image


 Copyright (C) 2016 Wiggins Lab 
 Written by Paul Wiggins.
 University of Washington, 2016
 This file is part of SuperSegger.
 
 SuperSegger is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 SuperSegger is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ws,num] = watershedNoise( im, minStep )
0002 % watershedNoise : uses watershed on an image and adds noise
0003 %
0004 % INPUT :
0005 %       im : input image.
0006 %       minStep : thershold value.
0007 % OUTPUT :
0008 %       ws : black and white watershed image
0009 %       num : max value in ws image
0010 %
0011 %
0012 % Copyright (C) 2016 Wiggins Lab
0013 % Written by Paul Wiggins.
0014 % University of Washington, 2016
0015 % This file is part of SuperSegger.
0016 %
0017 % SuperSegger is free software: you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation, either version 3 of the License, or
0020 % (at your option) any later version.
0021 %
0022 % SuperSegger is distributed in the hope that it will be useful,
0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 % GNU General Public License for more details.
0026 %
0027 % You should have received a copy of the GNU General Public License
0028 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0029 
0030 ws = watershed( im );
0031 run_flag = true;
0032 
0033 while run_flag
0034     
0035     run_flag = false;
0036     num = max(ws(:));    
0037     mins = zeros(1,num);
0038     zero_ind = find(ws==0);
0039     maxs = im(zero_ind);
0040     
0041     for ii = 1:num;
0042         mins(ii) = min(im(ws==ii));
0043     end
0044     
0045     hl = maxs'-mins(1:end-1);    
0046     indl = find( hl<minStep );
0047     
0048     if numel( indl )
0049         ii = indl(1);
0050         ws(zero_ind(ii)) = ii;
0051         ws(ws==(ii+1))=ii;
0052         run_flag = true;
0053     else
0054         
0055         hr = maxs'-mins(2:end);        
0056         indr = find( hr<minStep );
0057         
0058         if numel( indr )
0059             ii = indr(1);
0060             ws(zero_ind(ii)) = ii;
0061             ws(ws==(ii+1))=ii;
0062             run_flag = true;
0063         end 
0064     end
0065     ws = bwlabel(ws);   
0066 end
0067 
0068 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005