Home > SuperSegger > viz > makeFrameMosaic.m

makeFrameMosaic

PURPOSE ^

makeFrameMosaic: Creates a tower for a single cell.

SYNOPSIS ^

function [im] = makeFrameMosaic( data, CONST, xdim, disp_flag, skip )

DESCRIPTION ^

 makeFrameMosaic: Creates a tower for a single cell.
 The cell is shown masked. If CONST.view.orientFlag is true the cell 
 is oriented horizontally, it can be shown with FalseColor and
 in the fluorescent channel.

 INPUT :
       data : cell file
       CONST : segmentation parameters
       xdim : number of frames in a row in final image
       disp_flag : 1 to display image, 0 to not display iamge
       skip : frames to be skipped in final image

 OUTPUT :
       im : frame mosaic image

 Copyright (C) 2016 Wiggins Lab
 University of Washington, 2016
 This file is part of SuperSeggerOpti.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [im] = makeFrameMosaic( data, CONST, xdim, disp_flag, skip )
0002 % makeFrameMosaic: Creates a tower for a single cell.
0003 % The cell is shown masked. If CONST.view.orientFlag is true the cell
0004 % is oriented horizontally, it can be shown with FalseColor and
0005 % in the fluorescent channel.
0006 %
0007 % INPUT :
0008 %       data : cell file
0009 %       CONST : segmentation parameters
0010 %       xdim : number of frames in a row in final image
0011 %       disp_flag : 1 to display image, 0 to not display iamge
0012 %       skip : frames to be skipped in final image
0013 %
0014 % OUTPUT :
0015 %       im : frame mosaic image
0016 %
0017 % Copyright (C) 2016 Wiggins Lab
0018 % University of Washington, 2016
0019 % This file is part of SuperSeggerOpti.
0020 
0021 with_outline = 1;
0022 
0023 persistent strel1;
0024 if isempty( strel1 )
0025     strel1 = strel('disk',1);
0026 end
0027 
0028 persistent colormap_;
0029 if isempty( colormap_ )
0030     colormap_ = jet( 256 );
0031 end
0032 
0033 if ~exist('CONST', 'var' ) || isempty( CONST )
0034     CONST = loadConstants(60,0);
0035 end
0036 
0037 if ~exist('skip','var') || isempty( skip )
0038     skip = 1;
0039 end
0040 
0041 if ~exist('disp_flag', 'var' ) || isempty( disp_flag )
0042     disp_flag = true;
0043 end
0044 
0045 % orients the cell horizontally if true
0046 % keeps the orientation in the frame if false.
0047 if isfield( CONST, 'view' ) && isfield( CONST.view, 'orientFlag' )
0048     orientFlag = CONST.view.orientFlag;
0049 else
0050     orientFlag = true;
0051 end
0052 
0053 if ~isfield( CONST.view, 'background' );
0054     CONST.view.background = [0,0,0];
0055 end
0056 
0057 
0058 numframe = numel( data.CellA );
0059 TimeStep = CONST.getLocusTracks.TimeStep; % used when plotting the numbers
0060 imCell = cell( 1, numel(data.CellA) );
0061 alpha = zeros(1, numel(data.CellA) );
0062 ssCell = imCell;
0063 xxCell = imCell;
0064 yyCell = imCell;
0065 max_x = 0;
0066 max_y = 0;
0067 
0068 
0069 for ii = 1:numframe % go through all the frames
0070     
0071     if orientFlag % to orient horizontally
0072         if isfield( data.CellA{ii}, 'pole' ) && ~isnan( data.CellA{ii}.pole.op_ori ) && (data.CellA{ii}.pole.op_ori ~= 0)
0073             ssign = sign(data.CellA{ii}.pole.op_ori);
0074         else
0075             ssign = 1;
0076         end
0077         
0078         e1 = data.CellA{ii}.coord.e1;
0079         alpha(ii) = 90-180/pi*atan2(e1(1),e1(2)) + 180*double(ssign==1);
0080         
0081         mask = data.CellA{ii}.mask;
0082         mask = logical(imdilate(mask,strel1)); % dilate the mask
0083         rotated_mask = imrotate( double(mask), alpha(ii), 'bilinear' );
0084         
0085         summedMaskX = sum(rotated_mask);
0086         xmin_ = max([1,find(summedMaskX>0,1,'first')-1]);
0087         xmax_ = min([size(rotated_mask,2),find(summedMaskX>0,1, 'last')+1]);
0088         
0089         summedMaskY = sum(rotated_mask');
0090         ymin_ = max([1,find(summedMaskY>0,1,'first')-1]);
0091         ymax_ = min([size(rotated_mask,1),find(summedMaskY>0,1, 'last')+1]);
0092         
0093         yyCell{ii} = ymin_:ymax_;
0094         xxCell{ii} = xmin_:xmax_;
0095         
0096         try
0097             imCell{ii} = rotated_mask( ymin_:ymax_, xmin_:xmax_ );
0098         catch ME
0099             printError(ME);
0100         end
0101         
0102         ss = size(imCell{ii});
0103         ssCell{ii} = ss;
0104     else % non rotated mask
0105         imCell{ii} = data.CellA{ii}.mask;
0106         ss = size(data.CellA{ii}.mask);
0107         ssCell{ii} = ss;
0108     end
0109     
0110     max_x = max([max_x, ss(2)]);
0111     max_y = max([max_y, ss(1)]);
0112 end
0113 
0114 
0115 if exist( 'xdim', 'var') && ~isempty( xdim )
0116     nx = xdim;
0117     ny = ceil( numframe/nx/skip );
0118 else
0119     nx = ceil( sqrt( numframe*max_y/max_x/skip ) );
0120     ny = ceil( numframe/nx/skip );
0121 end
0122 
0123 max_x = max_x+1;
0124 max_y = max_y+1;
0125 
0126 
0127 imdim = [ max_y*ny + 1, max_x*nx + 1 ];
0128 im = uint8(zeros(imdim(1), imdim(2), 3 ));
0129 im1_= uint16(zeros(imdim(1), imdim(2)));
0130 im2_= uint16(zeros(imdim(1), imdim(2)));
0131 mask_mosaic = zeros(imdim(1), imdim(2));
0132 im_list = [];
0133 
0134 
0135 
0136 for ii = 1:skip:numframe
0137     
0138     yy = floor((ii-1)/nx/skip);
0139     xx = (ii-1)/skip-yy*nx;    
0140     ss = ssCell{ii};    
0141     dx = floor((max_x-ss(2))/2);
0142     dy = floor((max_y-ss(1))/2);
0143         
0144 
0145     if orientFlag
0146         mask = imCell{ii};
0147         mask = (imdilate( mask, strel1 ));
0148     else
0149         mask = data.CellA{ii}.mask;
0150         mask = (imdilate( mask, strel1 ));
0151     end
0152     
0153     mask_mosaic(1+yy*max_y+(1:ss(1))+dy, 1+xx*max_x+(1:ss(2))+dx) = mask;
0154     
0155         % fluor1
0156      if isfield( data.CellA{ii}, 'fluor1' )        
0157         if isfield( CONST.view, 'filtered' ) && ...
0158                 CONST.view.filtered && ...
0159                 isfield( data.CellA{ii}, 'fluor1_filtered' )           
0160             fluor1 =data.CellA{ii}.fluor1_filtered;
0161         else
0162             fluor1 = data.CellA{ii}.fluor1;            
0163             if isfield( data.CellA{ii}, 'fl1' ) && ...
0164                     isfield( data.CellA{ii}.fl1, 'bg' )
0165                 fluor1 = fluor1 - data.CellA{ii}.fl1.bg;
0166             end
0167         end
0168         
0169         fluor1 = imrotate(fluor1,alpha(ii),'bilinear');
0170         fluor1 = fluor1(yyCell{ii}, xxCell{ii});
0171         im1_(1+yy*max_y+(1:ss(1))+dy, 1+xx*max_x+(1:ss(2))+dx) = fluor1;        
0172         FLAG1 = true;
0173     else
0174         im1_ = 0*mask_mosaic;
0175         FLAG1 = false;
0176         f1mm = [0,1];
0177     end
0178     
0179        
0180     % fluor2
0181     flag2 = isfield( data.CellA{ii}, 'fluor2' );
0182     if isfield( data.CellA{ii}, 'fluor2' ) && 1
0183         
0184         if isfield( CONST.view, 'filtered' ) && ...
0185                 CONST.view.filtered && ...
0186                 isfield( data.CellA{ii}, 'fluor2_filtered' )
0187             
0188             fluor2 =data.CellA{ii}.fluor2_filtered;
0189         else
0190             fluor2 = data.CellA{ii}.fluor2;
0191         end
0192         
0193         fluor2 = imrotate(fluor2,alpha(ii),'bilinear');
0194         fluor2 = fluor2(yyCell{ii}, xxCell{ii});
0195         
0196         
0197         if isfield( data.CellA{ii}, 'fl2' ) && ...
0198                 isfield( data.CellA{ii}.fl2, 'bg' )
0199             fluor2 = fluor2 - data.CellA{ii}.fl2.bg;
0200             fluor2(fluor2<0) = 0;
0201         end
0202         
0203         im2_(1+yy*max_y+(1:ss(1))+dy, 1+xx*max_x+(1:ss(2))+dx) = fluor2;
0204         FLAG2 = true;
0205     else
0206         im2_ = uint8(0*mask_mosaic);
0207         FLAG2 = false;
0208         f2mm = [0,1];
0209     end
0210     
0211     
0212     if FLAG2
0213         im_list = [im_list, data.CellA{ii}.fluor1(:)', data.CellA{ii}.fluor2(:)'];
0214     elseif FLAG1
0215         im_list = [im_list, data.CellA{ii}.fluor1(:)'];
0216     else
0217         im_list = [im_list];
0218     end
0219 
0220 end
0221 
0222 
0223 % autogain the images
0224 im1_ = ag(im1_);
0225 im2_ = ag(im2_);
0226 disk1 = strel('disk',1);
0227 
0228 
0229 % different display methods
0230 if isfield(CONST.view, 'falseColorFlag') && ...
0231         CONST.view.falseColorFlag && ~flag2
0232     % false color image - only works if there is only one channel
0233     im    = ag(doColorMap( im1_, colormap_ ));
0234     back3 = uint8( cat( 3, double(CONST.view.background(1))*double(1-mask_mosaic),...
0235         double(CONST.view.background(2))*double(1-mask_mosaic),...
0236         double(CONST.view.background(3))*double(1-mask_mosaic)));
0237     mask3 = cat( 3, mask_mosaic, mask_mosaic, mask_mosaic );
0238     im = uint8(uint8( double(im).*mask3)+back3);
0239 elseif with_outline
0240     % plots normal mosaic with region outline
0241     del = 1;
0242     disk1 = strel('disk',1);   
0243     outer = imdilate(mask_mosaic, disk1).*double(~mask_mosaic);
0244     im = cat( 3, ...
0245         uint8(double(im2_).*mask_mosaic)+del*ag(1-mask_mosaic), ...
0246         uint8(double(im1_).*mask_mosaic)+del*ag(1-mask_mosaic), ...
0247         del*ag(1-mask_mosaic)+ag(outer));
0248 else
0249     del = 1;    
0250     disk1 = strel('disk',1);
0251     im = cat( 3, ...
0252         uint8(double(im2_).*mask_mosaic)+del*ag(1-mask_mosaic), ...
0253         uint8(double(im1_).*mask_mosaic)+del*ag(1-mask_mosaic), ...
0254         del*ag(1-mask_mosaic) );
0255 end
0256 
0257 
0258 
0259 
0260 inv_flag = 0;
0261 frameNumbers = 1:skip:numframe;
0262 
0263 if disp_flag
0264     figure(2);
0265     clf;
0266     if inv_flag
0267         imshow(255-im);
0268     else
0269         imshow(im);
0270     end
0271     
0272     if isfield( CONST.view, 'falseColorFlag' ) ...
0273             && CONST.view.falseColorFlag
0274         cc = 'w';
0275     else
0276         cc = 'b';
0277     end
0278        
0279     
0280     hold on;    
0281     for ii = 1:numel(frameNumbers)        
0282         yy = floor((ii-1)/nx);
0283         xx = ii-yy*nx-1;
0284         y = 1+yy*max_y;
0285         x = 1+xx*max_x;                
0286         text( x+2, y+2, num2str(frameNumbers(ii)*TimeStep),'Color',[0.5, 0.5, 1],'FontSize',15,'VerticalAlignment','Top');
0287     end
0288     
0289     
0290     dd = [1,ny*max_y+1];
0291     for xx = 1:(nx-1)
0292         plot( 0*dd + 1+xx*max_x, dd,[':',cc]);
0293     end
0294     
0295     dd = [1,nx*max_x+1];
0296     for yy = 1:(ny-1)
0297         plot( dd, 0*dd + 1+yy*max_y, [':',cc]);
0298     end
0299 end
0300 
0301 
0302 end
0303 
0304

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