towerMergeImages : merges the towers of several cells. INPUT : imCell : cell array of individual cell images maskCell : image of tower mask ssCell : width and length of cells xdim : x dimensions for the towers skip : skip frame mag : used to set up the image dimensions CONST : Constants file that was used. OUTPUT : imColor : rescaled color (jet) consensus image imBW : rescaled bw consesus image towerIm : raw consensus image maskCons : mask for consensus image nx : number of cells in x ny : number of cells in y max_x : max long axis length max_y : max short axis length Copyright (C) 2016 Wiggins Lab Written by Stella Stylianidou, 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/>.
0001 function [imColor, imBW, towerIm, maskCons, nx, ny, max_x, max_y ] = ... 0002 towerMergeImages( imCell, maskCell, ssCell, xdim, skip, mag, CONST ) 0003 % towerMergeImages : merges the towers of several cells. 0004 % 0005 % INPUT : 0006 % imCell : cell array of individual cell images 0007 % maskCell : image of tower mask 0008 % ssCell : width and length of cells 0009 % xdim : x dimensions for the towers 0010 % skip : skip frame 0011 % mag : used to set up the image dimensions 0012 % CONST : Constants file that was used. 0013 % 0014 % OUTPUT : 0015 % imColor : rescaled color (jet) consensus image 0016 % imBW : rescaled bw consesus image 0017 % towerIm : raw consensus image 0018 % maskCons : mask for consensus image 0019 % nx : number of cells in x 0020 % ny : number of cells in y 0021 % max_x : max long axis length 0022 % max_y : max short axis length 0023 % 0024 % Copyright (C) 2016 Wiggins Lab 0025 % Written by Stella Stylianidou, Paul Wiggins. 0026 % University of Washington, 2016 0027 % This file is part of SuperSegger. 0028 % 0029 % SuperSegger is free software: you can redistribute it and/or modify 0030 % it under the terms of the GNU General Public License as published by 0031 % the Free Software Foundation, either version 3 of the License, or 0032 % (at your option) any later version. 0033 % 0034 % SuperSegger is distributed in the hope that it will be useful, 0035 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0036 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0037 % GNU General Public License for more details. 0038 % 0039 % You should have received a copy of the GNU General Public License 0040 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0041 0042 0043 0044 0045 if ~exist('skip','var') || isempty (skip) 0046 skip = 1; 0047 end 0048 0049 colormap_ = jet(256); 0050 max_x = 0; 0051 max_y = 0; 0052 0053 0054 % get number of time slices. 0055 T0 = numel(ssCell); 0056 0057 for ii = 1:T0 0058 max_x = max([max_x, ssCell{ii}(2)]); 0059 max_y = max([max_y, ssCell{ii}(1)]); 0060 end 0061 0062 0063 if exist( 'xdim', 'var') && ~isempty(xdim) 0064 nx = xdim; 0065 ny = ceil(T0/nx/skip); 0066 else 0067 nx = ceil(sqrt(T0*max_y/max_x/skip)); 0068 ny = ceil(T0/nx/skip); 0069 end 0070 0071 max_x = max_x+mag; 0072 max_y = max_y+mag; 0073 0074 imdim = [ max_y*ny + mag, max_x*nx + mag ]; 0075 0076 maskCons = zeros(imdim(1), imdim(2)); 0077 towerIm = zeros(imdim(1), imdim(2)); 0078 0079 % make the composite image 0080 for ii = 1:T0 0081 0082 yy = floor((ii-1)/nx/skip); 0083 xx = floor((ii-1)/skip)-yy*nx; 0084 0085 ss = ssCell{ii}; 0086 0087 dx = floor((max_x-ss(2))/2); 0088 dy = floor((max_y-ss(1))/2); 0089 0090 mask = maskCell{ii}; 0091 0092 try 0093 maskCons(1+yy*max_y+(1:ss(1))+dy, 1+xx*max_x+(1:ss(2))+dx) = mask; 0094 towerIm(1+yy*max_y+(1:ss(1))+dy, 1+xx*max_x+(1:ss(2))+dx) = imCell{ii}; 0095 catch ME 0096 printError(ME); 0097 disp( 'Error in towerMergeImages' ); 0098 end 0099 end 0100 0101 % rescale the dynamic range of the image. 0102 f1mm = [min(towerIm( maskCons(:)>.5 )), max( towerIm( maskCons(:)>.5 ))]; 0103 imBW = ag(towerIm.*maskCons,0,f1mm(2)); 0104 0105 0106 if CONST.view.falseColorFlag 0107 % make the false color image 0108 imColor = ag(doColorMap( imBW, colormap_ )); 0109 mask3 = cat( 3, maskCons, maskCons, maskCons ); 0110 imColor = uint8(uint8( double(imColor).*mask3)); 0111 else 0112 % make normal image 0113 del = 0.15; 0114 imColor = cat( 3, ... 0115 0*maskCons, ... 0116 uint8(double(imBW).*maskCons), ... 0117 del*ag(maskCons) ); 0118 end 0119 0120 end 0121 0122