Home > SuperSegger > segmentation > makeBgMask.m

makeBgMask

PURPOSE ^

makeBgMask : makes a background mask for the phase image

SYNOPSIS ^

function mask = makeBgMask(phase, filt_3, filt_4, AREA, CONST, crop_box)

DESCRIPTION ^

 makeBgMask : makes a background mask for the phase image

 INPUT :
       phase : phase image
       filt_3 : first filter with bigger size and std
       filt_4 : second filter with smaller size and std
       AREA : the minimum area of cells/cell clumps
       CONST : segmentation constants
       crop_box : information about alignement of the image

 OUTPUT :
       mask : image masking background as black and cells as white


 Copyright (C) 2016 Wiggins Lab 
 Written by Paul Wiggins & Stella Stylianidou.
 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function mask = makeBgMask(phase, filt_3, filt_4, AREA, CONST, crop_box)
0002 % makeBgMask : makes a background mask for the phase image
0003 %
0004 % INPUT :
0005 %       phase : phase image
0006 %       filt_3 : first filter with bigger size and std
0007 %       filt_4 : second filter with smaller size and std
0008 %       AREA : the minimum area of cells/cell clumps
0009 %       CONST : segmentation constants
0010 %       crop_box : information about alignement of the image
0011 %
0012 % OUTPUT :
0013 %       mask : image masking background as black and cells as white
0014 %
0015 %
0016 % Copyright (C) 2016 Wiggins Lab
0017 % Written by Paul Wiggins & Stella Stylianidou.
0018 % University of Washington, 2016
0019 % This file is part of SuperSegger.
0020 %
0021 % SuperSegger is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % SuperSegger is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 crop_box = round( crop_box );
0035 crop_rad = CONST.superSeggerOpti.crop_rad;
0036 THRESH1  = CONST.superSeggerOpti.THRESH1; % to remove background
0037 THRESH2  = CONST.superSeggerOpti.THRESH2; % to remove background between cells
0038 Amax     = CONST.superSeggerOpti.Amax;
0039 
0040 % applies the two filters
0041 im_filt3 = imfilter(double(phase),filt_3,'replicate');
0042 im_filt4 = imfilter(double(phase),filt_4,'replicate');
0043 
0044 tmp      = uint16(-(im_filt4-im_filt3));
0045 nnn      = ag(tmp);
0046 
0047 % intensity thresholding to get the cell colonies
0048 % dilating and filling the areas below Amax
0049 maskth1    = imdilate(nnn>THRESH1,strel('disk',5));
0050 maskth1    = fill_max_area( maskth1, Amax );
0051 
0052 % dilated mask for values above low threshold
0053 % emphasizes the structure in cells and background
0054 maskth2     = imdilate(nnn>THRESH2,strel('disk',1));
0055 
0056 % Logical and of two masks where the two masks match
0057 mask     = and(maskth2,maskth1);
0058 
0059 % dilate, fills the max area, and erodes
0060 mask     = imdilate( mask, strel('disk',2));
0061 mask     = fill_max_area( mask, Amax );
0062 mask     = imerode( mask, strel('disk',crop_rad));
0063 
0064 % remove from mask objects with area smaller than AREA
0065 cc       = bwconncomp(mask);
0066 stats    = regionprops(cc, 'Area');
0067 idx      = find([stats.Area] > AREA);
0068 mask     = ismember(labelmatrix(cc), idx);
0069 
0070 
0071 if ~isempty( crop_box );
0072     mask(:,1:crop_box(2))   = false;
0073     mask(:,crop_box(4):end) = false;
0074     mask(1:crop_box(1),:)   = false;
0075     mask(crop_box(3):end,:) = false;
0076     
0077     mask(:,1:crop_box(2))   = false;
0078     mask(:,crop_box(4):end) = false;
0079     mask(1:crop_box(1),:)   = false;
0080     mask(crop_box(3):end,:) = false;
0081 end
0082 
0083 end
0084 
0085 function mask_fill = fill_max_area( mask, maxA )
0086 % fill_max_area
0087 
0088 fmask     = imfill( mask, 'holes' );
0089 filled    = fmask.*~mask;
0090 cc = bwconncomp(filled);
0091 stats = regionprops(cc, 'Area');
0092 idx = find([stats.Area] < maxA);
0093 added = ismember(labelmatrix(cc), idx);
0094 mask_fill = or(mask,added);
0095 
0096 end

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