Home > SuperSegger > segmentation > magicContrast.m

magicContrast

PURPOSE ^

magicContrast : applies a filter to enhance inter-cellular contrast.

SYNOPSIS ^

function imMagic = magicContrast( im, radius )

DESCRIPTION ^

 magicContrast : applies a filter to enhance inter-cellular contrast.
 It is local minimum filter (similar to a median filter) to enhance contrast.
 It is subtracting from each pixel the minimum intensity in its neighborhood.
 It forces the interior of the cells closer to zero intensity. Used to create
 a background mask.

 INPUT :
       im : phase image
       radius : radius to be used to apply contrast
 OUTPUT :
       im : phase image with applied contrast

 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 imMagic = magicContrast( im, radius )
0002 % magicContrast : applies a filter to enhance inter-cellular contrast.
0003 % It is local minimum filter (similar to a median filter) to enhance contrast.
0004 % It is subtracting from each pixel the minimum intensity in its neighborhood.
0005 % It forces the interior of the cells closer to zero intensity. Used to create
0006 % a background mask.
0007 %
0008 % INPUT :
0009 %       im : phase image
0010 %       radius : radius to be used to apply contrast
0011 % OUTPUT :
0012 %       im : phase image with applied contrast
0013 %
0014 % Copyright (C) 2016 Wiggins Lab
0015 % Written by Paul Wiggins.
0016 % University of Washington, 2016
0017 % This file is part of SuperSegger.
0018 %
0019 % SuperSegger is free software: you can redistribute it and/or modify
0020 % it under the terms of the GNU General Public License as published by
0021 % the Free Software Foundation, either version 3 of the License, or
0022 % (at your option) any later version.
0023 %
0024 % SuperSegger is distributed in the hope that it will be useful,
0025 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0026 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0027 % GNU General Public License for more details.
0028 %
0029 % You should have received a copy of the GNU General Public License
0030 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0031 
0032 
0033 si = size( im );
0034 
0035 impad = [im(radius:-1:1,radius:-1:1), im(radius:-1:1,:), ...
0036     im(radius:-1:1,end:-1:(end-radius));...
0037     im(:, radius:-1:1), im(:, :), im(:,end:-1:(end-radius));...
0038     im(end:-1:end-radius,radius:-1:1), im(end:-1:end-radius,:), ...
0039     im(end:-1:end-radius, end:-1:(end-radius))];
0040 
0041 xx = (-radius):(radius);
0042 
0043 [X,Y] = meshgrid( xx, xx);
0044 mini_mask = ( X.^2+Y.^2 <= radius^2 );
0045 
0046 rr = 1:si(1);
0047 cc = 1:si(2);
0048 first_time_flag = 1;
0049 
0050 for ii = (-radius):(radius)
0051     for jj = (-radius):(radius)
0052         if mini_mask(ii+radius+1,jj+radius+1);            
0053             if first_time_flag
0054                 minpad = impad(rr+radius+ii,cc+radius+jj);
0055                 first_time_flag = 0;
0056             else
0057                 minpad = min(minpad,impad(rr+radius+ii,cc+radius+jj));
0058             end
0059         end
0060     end
0061 end
0062 
0063 imMagic = im-minpad;
0064 imMagic(imMagic<0) = 0;
0065 
0066 end
0067

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