Home > SuperSegger > viz > showSeggerImage.m

showSeggerImage

PURPOSE ^

showSeggerImage : produces the superSeggerViewer image according to clist and

SYNOPSIS ^

function im = showSeggerImage( data, data_r, data_f, FLAGS, clist, CONST, gui_fig)

DESCRIPTION ^

 showSeggerImage : produces the superSeggerViewer image according to clist and
 flags. If the clist has a gate it outlines cells passing the gate.

 Colors : green are cells without errors, red are cells with error flags
 reverse or forward, or lysed cells, blue are cells that came from a good
 division, if error or not observed (?), or had a succesfful divison.

 INPUT :
         data : current frame data (*err usually data)
         data_r : reverse frame data
         data_f : forward frame data
         FLAGS : controls what is displays, for more information look at fixFlags
         clist : list of cell files, could have a gate field.
         CONST : segmentation constants


 OUTPUT :
         im : trackOptiView outlined image


 Copyright (C) 2016 Wiggins Lab
 Written by Stella Stylianidou, Paul Wiggins, Connor Brennan.
 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 im = showSeggerImage( data, data_r, data_f, FLAGS, clist, CONST, gui_fig)
0002 % showSeggerImage : produces the superSeggerViewer image according to clist and
0003 % flags. If the clist has a gate it outlines cells passing the gate.
0004 %
0005 % Colors : green are cells without errors, red are cells with error flags
0006 % reverse or forward, or lysed cells, blue are cells that came from a good
0007 % division, if error or not observed (?), or had a succesfful divison.
0008 %
0009 % INPUT :
0010 %         data : current frame data (*err usually data)
0011 %         data_r : reverse frame data
0012 %         data_f : forward frame data
0013 %         FLAGS : controls what is displays, for more information look at fixFlags
0014 %         clist : list of cell files, could have a gate field.
0015 %         CONST : segmentation constants
0016 %
0017 %
0018 % OUTPUT :
0019 %         im : trackOptiView outlined image
0020 %
0021 %
0022 % Copyright (C) 2016 Wiggins Lab
0023 % Written by Stella Stylianidou, Paul Wiggins, Connor Brennan.
0024 % University of Washington, 2016
0025 % This file is part of SuperSegger.
0026 %
0027 % SuperSegger is free software: you can redistribute it and/or modify
0028 % it under the terms of the GNU General Public License as published by
0029 % the Free Software Foundation, either version 3 of the License, or
0030 % (at your option) any later version.
0031 %
0032 % SuperSegger is distributed in the hope that it will be useful,
0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0035 % GNU General Public License for more details.
0036 %
0037 % You should have received a copy of the GNU General Public License
0038 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0039 
0040 iptsetpref('imshowborder','tight');
0041 iptsetpref('ImshowInitialMagnification','fit');
0042 
0043 if ~exist('CONST','var') || isempty(CONST)
0044     disp ('No constants loaded - loading 60XEcLb');
0045     CONST = loadConstants(60,0);
0046 end
0047 
0048 if ~isfield(CONST.view, 'falseColorFlag' )
0049     CONST.view.falseColorFlag = false;
0050 end
0051 
0052 if nargin<4
0053     FLAGS = [];
0054 end
0055 
0056 FLAGS.axis = axis;
0057 
0058 if ~exist('gui_fig','var') || isempty(gui_fig)
0059     gui_fig = [];
0060     clf;
0061 end
0062 
0063 % fix are any missing flags
0064 FLAGS = intFixFlags( FLAGS );
0065 
0066 % if there is a clist enables look only cells included in the clist
0067 if exist('clist','var') && ~isempty( clist );
0068     clist = gate( clist );
0069     ID_LIST = clist.data(:,1);
0070     ID_LIST = ID_LIST(logical(ID_LIST));
0071 else
0072     clist = [];
0073     if isfield(data, 'regs') && isfield( data.regs, 'ID' );
0074         ID_LIST = data.regs.ID;
0075     else
0076         ID_LIST = [];
0077     end
0078 end
0079 
0080 
0081 [xx,yy] = intGetImSize( data, FLAGS );
0082 mask_full = data.mask_cell;
0083 im = makeIm( data, FLAGS, ID_LIST, CONST );
0084 
0085 if FLAGS.m_flag % mask flag : shows reverse, forward, current, and masked image view
0086     if isempty(data_r)
0087         mask_full_r = 0*mask_full;
0088         im_r = cat(3,mask_full_r,mask_full_r,mask_full_r);
0089     else
0090         mask_full_r = data_r.mask_cell;
0091         im_r = makeIm( data_r, FLAGS );
0092     end
0093     
0094     if isempty(data_f)
0095         mask_full_f = 0*mask_full;
0096         im_f = cat(3,mask_full_f,mask_full_f,mask_full_f);
0097     else
0098         mask_full_f = data_f.mask_cell;
0099         im_f = makeIm( data_f, FLAGS );
0100     end
0101     
0102     im =  [im_r(yy,xx,:),im(yy,xx,:); im_f(yy,xx,:), ...
0103         cat(3, 0.5*ag(mask_full_r(yy,xx)>0),...
0104         0.5*ag(mask_full(yy,xx)>0),...
0105         0.5*ag(mask_full_f(yy,xx)>0))];
0106 end
0107 
0108 if isempty(gui_fig)
0109     imshow(im)
0110 else
0111     axes(gui_fig);
0112     imshow(im);
0113     FLAGS.axis = axis;
0114 end
0115 hold on;
0116 
0117 
0118 b = gca; legend(b,'off');
0119 
0120 if FLAGS.P_flag && FLAGS.legend
0121     hold on;
0122     dark_blue = [20 20 199]/255;
0123     light_blue = [20 97 199]/255;
0124     cyan = [36 113 125]/255;
0125     green = [18 95 63]/255;
0126     purple = [105 60 106]/255;
0127     ha(1) = plot(nan,nan,'o','MarkerSize',10,'MarkerEdgeColor',green,'MarkerFaceColor',green);
0128     ha(2) = plot(nan,nan,'o','MarkerSize',10,'MarkerEdgeColor',dark_blue,'MarkerFaceColor',dark_blue);
0129     ha(3) = plot(nan,nan,'o','MarkerSize',10,'MarkerEdgeColor',light_blue,'MarkerFaceColor',light_blue);
0130     ha(4) = plot(nan,nan,'o','MarkerSize',10,'MarkerEdgeColor',purple,'MarkerFaceColor',purple);
0131     ha(5) = plot(nan,nan,'-r');
0132     
0133     hhh = legend(ha',{'No birth', 'No division', 'Full cell cycle', 'Errors','Dividing'},...
0134         'Location','NorthEast',...
0135         ... %'BestOutside',
0136         'Orientation','vertical');
0137     set( hhh, 'EdgeColor', [ 0,   0,   0],...
0138         'Color',     [ 0.8, 0.8, 0.8],...
0139         'TextColor', [ 0,   0,   0] );
0140     
0141 end
0142 
0143 % Displays linking information
0144 if FLAGS.showLinks
0145     intPlotLinks(data, data_r, data_f, -xx(1)+1, -yy(1)+1, FLAGS, ID_LIST, CONST );
0146     hold on;
0147 end
0148 
0149 % annotates spots, cell numbers and poles
0150 if ~FLAGS.m_flag
0151     doAnnotation( data, -xx(1)+1, -yy(1)+1 );
0152 else
0153     doAnnotation( data, -xx(1)+xx(end)-xx(1)+1, -yy(1)+1 );
0154     doAnnotation( data_r , -xx(1)+1, -yy(1)+1);
0155     doAnnotation( data_f , -xx(1)+1, -yy(1)+yy(end)-yy(1)+1 );
0156     doFrameMerge( -xx(1)+xx(end)-xx(1)+1+1, -yy(1)+yy(end)-yy(1)+1+1);
0157 end
0158 
0159 
0160 
0161 
0162     function doAnnotation( data_, x_, y_ )
0163         % doAnnotation : annotates spots, cell numbers and poles
0164         if ~isempty(data_)
0165             if FLAGS.ID_flag == 1 % plots cell numbers
0166                 intPlotNum( data_ , x_, y_, FLAGS, ID_LIST );
0167             elseif FLAGS.regionScores % plots region scores
0168                 intPlotScores( data_ , x_, y_, FLAGS );
0169             end
0170             
0171             % plots spots, only if we are at fluorescence view
0172             if FLAGS.f_flag && FLAGS.s_flag && isfield(data_,'CellA')
0173                 intPlotSpot( data_, x_, y_, FLAGS, ID_LIST, CONST );
0174             end
0175             
0176             % plots poles
0177             if FLAGS.p_flag
0178                 intPlotPole( data_, x_, y_, FLAGS);
0179             end
0180         end
0181     end
0182 
0183 
0184     function doFrameMerge( x_, y_ )
0185         
0186         if ~isempty( data )
0187             for kk = 1:data.regs.num_regs
0188                 rr3 = [x_,y_ ];
0189                 rr_c = data.regs.props(kk).Centroid;
0190                 
0191                 try
0192                     if isfield(data.regs,'ID') && data.regs.ID(kk)
0193                         ID  = data.regs.ID(kk);
0194                         if ~isempty(data_r) && isfield(data_r.regs,'ID')
0195                             ind_r = find(ID == data_r.ID);
0196                             if ~isempty( ind_r );
0197                                 rr_r = data_r.props(ind_r).Centroid ;
0198                                 plot( [rr_c(1),rr_r(1)]+rr3(1), [rr_c(2),rr_r(2)]+rr3(2), 'r');
0199                             end
0200                         end
0201                         
0202                         if ~isempty(data_f) && isfield(data_f.regs,'ID')
0203                             ind_f = find(ID == data_f.ID);
0204                             if ~isempty( ind_f );
0205                                 rr_f = data_f.props(ind_f).Centroid ;
0206                                 plot( [rr_c(1),rr_f(1)]+rr3(1), [rr_c(2),rr_f(2)]+rr3(2), 'b');
0207                             end
0208                         end
0209                     end
0210                     
0211                 catch ME
0212                     printEroor(ME);
0213                 end
0214             end
0215             
0216         end
0217     end
0218 
0219 
0220 end
0221 
0222 
0223 function im = makeIm( data, FLAGS, ID_LIST, CONST )
0224 % makeIm puts together the image if data is segmented
0225 % but not the text/pole/other labels.
0226 % INPUT :
0227 % data : is a loaded seg or trk file with region info
0228 % FLAGS : are the flags used for image plotting
0229 % ID_LIST : are the ids of cells selected through a clist
0230 % CONST : are the segmentation constants
0231 
0232 persistent colormap_;
0233 if isempty( colormap_ )
0234     colormap_ = colormap( 'jet' );
0235 end
0236 
0237 % get the image size
0238 ss = size(data.phase);
0239 
0240 
0241 % if the phase image exists use this as the background, else use the cell
0242 % masks
0243 phase_level = FLAGS.phase_level;
0244 if isfield(data,'phase') && FLAGS.phase_flag
0245     back = phase_level * ag(data.phase);
0246     im = cat(3,back,back,back);
0247 else
0248     mask = phase_level * ag(~data.mask_cell);
0249     im = cat(3, mask,mask,mask);
0250 end
0251 
0252 
0253 % this code highlights the lysed cells
0254 if isfield( data, 'regs' ) && isfield( data.regs, 'lyse' ) && FLAGS.lyse_flag
0255     is_lyse = and( or( data.regs.lyse.errorColor1bCum, ...
0256         data.regs.lyse.errorColor2bCum), data.regs.lyse.errorShapeCum);
0257     lyse_im = intDoOutline2(ismember( ...
0258         data.regs.regs_label,find(is_lyse)));
0259 else
0260     lyse_im = zeros( ss );
0261 end
0262 
0263 
0264 
0265 % if you are in fluorescence mode (f_flag) draw the fluor channels
0266 if FLAGS.composite
0267     nc = numel(find(~cellfun('isempty',strfind(fieldnames(data),'fluor'))));
0268     
0269     for i = 1 : nc
0270         im = updateFluorImage(data, im, i, FLAGS, CONST);
0271     end
0272     
0273 elseif FLAGS.f_flag > 0
0274     im = updateFluorImage(data, im, FLAGS.f_flag, FLAGS, CONST);
0275 end
0276 
0277 if FLAGS.Outline_flag  % it just outlines the cells
0278     if FLAGS.cell_flag && isfield(data,'cell_outline')
0279         im(:,:,:) = im(:,:,:) + cat(3,0.4*ag(data.cell_outline),0.4*ag(data.cell_outline),0.5*ag(data.cell_outline));
0280     elseif isfield(data,'outline')
0281         im(:,:,:) = im(:,:,:) + cat(3,0.3*ag(data.outline),0.3*ag(data.outline),0.5*ag(data.outline));
0282     elseif isfield(data,'mask_cell')% no outline field (not loaded through super segger viewer)
0283         data.outline = xor(bwmorph( data.mask_cell,'dilate'), data.mask_cell);
0284         im(:,:,:) = im(:,:,:) + cat(3,0.3*ag(data.outline),0.3*ag(data.outline),0.5*ag(data.outline));
0285     end
0286     
0287 elseif FLAGS.P_flag  % if P_flag is true, it shows the regions with color.
0288     
0289     if ~isfield( data,'regs') || ~isfield( data.regs, 'ID') % no cell ids - seg files
0290         
0291         blueChannel = 0.3*(data.mask_cell);
0292         reg_color = uint8( 255*cat(3, 0*blueChannel,blueChannel,blueChannel));
0293         im = reg_color + im;
0294         
0295     else
0296         
0297         if isfield( data.regs, 'ignoreError' )
0298             ignoreErrorV = data.regs.ignoreError;
0299         else
0300             ignoreErrorV = 0*data.reg.divide;
0301         end
0302         
0303         % cells in the ID list and in this region
0304         % if v_flag is off, all cells are in is_in_cell_V
0305         cells_In_Frame   = ismember( data.regs.ID, ID_LIST);
0306         cellBorn = or(and(data.regs.birthF,data.regs.stat0),data.regs.divide);
0307         
0308         if ~isempty(cells_In_Frame)
0309             % cells with ehist & error current->reverse or ignoreError
0310             map_error_ind = find(and(cells_In_Frame,or(and(data.regs.ehist,...
0311                 data.regs.error.r),ignoreErrorV)));
0312             map_err_rev  = double(ismember( data.regs.regs_label, map_error_ind ));
0313             
0314             % cells with ehist in this frame, but no error current->reverse or ignoreError
0315             map_ehist_in_frame_ind = find(and(cells_In_Frame,or(and(data.regs.ehist,...
0316                 ~data.regs.error.r),ignoreErrorV)));
0317             map_ehist_in_frame  = double(ismember( data.regs.regs_label, map_ehist_in_frame_ind ));
0318             
0319             
0320             % cells without error history
0321             map_no_err_ind =  find(and(cells_In_Frame,or(~data.regs.ehist,ignoreErrorV)));
0322             map_no_err  = double(ismember( data.regs.regs_label, map_no_err_ind));
0323             
0324             % in list, cell was not born in this frame with good division or divided
0325             % but stat0==2 : succesfful division was observed
0326             map_stat0_2_ind = find(and(cells_In_Frame,data.regs.stat0==2));
0327             map_stat0_2 = double(ismember( data.regs.regs_label,map_stat0_2_ind ));
0328             
0329             % outline the ones that were just born with stat0 == 2
0330             map_stat0_2O_ind = find(and(cells_In_Frame,and(cellBorn,data.regs.stat0==2)));
0331             map_stat0_2_Outline = intDoOutline2(ismember(data.regs.regs_label, map_stat0_2O_ind));
0332             
0333             
0334             % in list, cell was not born in this frame with good division or divided
0335             % stat0==1 : cell was result of succesfful division
0336             map_stat0_1_ind  = find(and(cells_In_Frame,data.regs.stat0==1));
0337             map_stat0_1  = double( ismember( data.regs.regs_label,map_stat0_1_ind ));
0338             
0339             % outline the ones that were just born with stat0 == 1
0340             map_stat0_1O_ind = find(and(cells_In_Frame,and(cellBorn,data.regs.stat0==1)));
0341             map_stat0_1_Outline = intDoOutline2(ismember(data.regs.regs_label, map_stat0_1O_ind));
0342             
0343             
0344             % in list, cell was not born in this frame with good division or divided
0345             % stat0 == 0  : cell has errors, or division not observed
0346             map_stat0_0_ind = find(and(cells_In_Frame,data.regs.stat0==0));
0347             map_stat0_0 = double(ismember( data.regs.regs_label, map_stat0_0_ind ));
0348             
0349             % outline the ones that were just born with stat0 == 1
0350             map_stat0_0O_ind = find(and(cells_In_Frame,and(cellBorn,data.regs.stat0==0)));
0351             map_stat0_0_Outline = intDoOutline2(ismember(data.regs.regs_label, map_stat0_0O_ind));
0352             
0353             
0354             
0355             redChannel =  double(lyse_im)+0.5*(0.7*(map_err_rev)+1.1*(map_ehist_in_frame)+.7*(map_stat0_2_Outline+map_stat0_1_Outline +map_stat0_0_Outline));
0356             greenChannel =  0.3*(map_no_err) - 0.2*(map_stat0_1)+0.2*(map_stat0_0);
0357             blueChannel = 0.7*(map_stat0_2)+ 0.6*(map_stat0_1)+0.3*(map_stat0_0);
0358             
0359             reg_color = uint8( 255*cat(3, redChannel,greenChannel,blueChannel));
0360             
0361             im = reg_color + im;
0362         end
0363     end
0364     %% colors :
0365     % baby-blue : no errors, stat0=2 cells
0366     % tirquaz :  stat0 = 1 cells
0367     % deep green : stat0 = 0 cells
0368     % pink : has error in reverse frame
0369     % purple : has error in forward frame
0370     % red outlines : dividing or has just divided
0371     
0372 end
0373 
0374 end
0375 
0376 
0377 function im = updateFluorImage(data, im, channel, FLAGS, CONST)
0378 
0379 fluorName =  ['fluor',num2str(channel)];
0380 
0381 fluorName =  ['fluor',num2str(channel)];
0382 flbgName =  ['fl',num2str(channel),'bg'];
0383 if isfield(data, fluorName )
0384     if ~isfield (CONST.view,'fluorColor')
0385         CONST.view.fluorColor = {'g','r','b'};
0386     end
0387     
0388     curColor = getRGBColor( CONST.view.fluorColor{channel});
0389     
0390     if FLAGS.filt && isfield( data, [fluorName,'_filtered'] )
0391         fluor_tmp =  data.([fluorName,'_filtered']);
0392     else
0393         fluor_tmp = data.(fluorName);
0394         if isfield( data, 'fl1bg' )
0395             fluor_tmp = fluor_tmp - data.(flbgName);
0396             fluor_tmp( fluor_tmp< 0 ) = 0;
0397         else
0398             fluor_tmp = fluor_tmp-mean(fluor_tmp(:));
0399             fluor_tmp( fluor_tmp< 0 ) = 0;
0400         end
0401     end
0402     
0403     if isfield( CONST.view, 'LogView' ) && CONST.view.LogView && ~FLAGS.composite
0404         fluor_tmp =   ag( double(fluor_tmp).^.6 );
0405     end
0406     
0407     
0408     minner = medfilt2( fluor_tmp, [2,2], 'symmetric' );
0409     maxxer = max( minner(:));
0410     minner = min( minner(:));
0411     if CONST.view.falseColorFlag
0412         im = im + doColorMap( ag(fluor_tmp,minner,maxxer), uint8(255*jet(256)) );
0413     else
0414         imFluor = 0.8*ag(fluor_tmp,minner,maxxer);
0415         im(:,:,1) = im(:,:,1) + curColor(1) * imFluor;
0416         im(:,:,2) = im(:,:,2) + curColor(2) * imFluor;
0417         im(:,:,3) = im(:,:,3) + curColor(3) * imFluor;
0418     end
0419     
0420     
0421 end
0422 end
0423 
0424 
0425 function intPlotScores( data, x_, y_ , FLAGS )
0426 % intPlotNum : Plot cell number or region numbers
0427 
0428 counter = 200; % max amount of cell numbers to be plotted
0429 kk = 0; % counter for regions
0430 while (counter > 0 && kk < data.regs.num_regs)
0431     % disp(counter)
0432     kk = kk + 1;
0433     rr = data.regs.props(kk).Centroid;
0434     
0435     if isfield( data.regs, 'ignoreError' )
0436         ignoreError = data.regs.ignoreError(kk);
0437     else
0438         ignoreError = 0;
0439     end
0440     
0441     score = 1 - (data.regs.scoreRaw(kk) + 50) / 100;
0442     
0443     colorMap = spring(256);
0444     colorIndex = floor(min(score, 1) * 255) + 1;
0445     
0446     xpos = rr(1)+x_;
0447     ypos = rr(2)+y_;
0448     
0449     if (FLAGS.axis(1)<xpos) && (FLAGS.axis(2)>xpos) && ...
0450             (FLAGS.axis(3)<ypos) && (FLAGS.axis(4)>ypos)
0451         
0452         counter = counter - 1;
0453         
0454         text( xpos, ypos, ['\fontsize{11}',num2str(data.regs.scoreRaw(kk), 2)],...
0455             'Color', [colorMap(colorIndex, 1), colorMap(colorIndex, 2), colorMap(colorIndex, 3)],...
0456             'FontWeight', 'normal',...
0457             'HorizontalAlignment','Center',...
0458             'VerticalAlignment','Middle');
0459         title('Region Scores');
0460     end
0461     
0462 end
0463 end
0464 
0465 function intPlotNum( data, x_, y_ , FLAGS, ID_LIST )
0466 % intPlotNum : Plot cell number or region numbers
0467 
0468 counter = 1000; % max amount of cell numbers to be plotted
0469 kk = 0; % counter for regions
0470 xpos_id =[];
0471 ypos_id = [];
0472 str_id = {};
0473 color = [];
0474 while (counter > 0 && kk < data.regs.num_regs)
0475     % disp(counter)
0476     kk = kk + 1;
0477     rr = data.regs.props(kk).Centroid;
0478     
0479     if isfield( data.regs, 'ignoreError' )
0480         ignoreError = data.regs.ignoreError(kk);
0481     else
0482         ignoreError = 0;
0483     end
0484     
0485     setRed = false;
0486     if isfield (data.regs, 'error') && data.regs.error.r(kk)
0487         setRed = true;
0488     end
0489     
0490     xpos = rr(1)+x_;
0491     ypos = rr(2)+y_;
0492     
0493     if (FLAGS.axis(1)<xpos) && (FLAGS.axis(2)>xpos) && ...
0494             (FLAGS.axis(3)<ypos) && (FLAGS.axis(4)>ypos)
0495         
0496         counter = counter - 1;
0497         if FLAGS.cell_flag == 1 && isfield( data.regs, 'ID' )
0498             xpos_id = [xpos_id;xpos];
0499             ypos_id = [ypos_id;ypos];
0500             if setRed
0501                 str_id{end+1} = ['{\color{red}',num2str(data.regs.ID(kk)),'}'];
0502             else
0503                 str_id{end+1} = num2str(data.regs.ID(kk));
0504             end
0505             
0506         else % region view cell_flag is 0
0507             xpos_id = [xpos_id;xpos];
0508             ypos_id = [ypos_id;ypos];
0509             if setRed
0510                 str_id{end+1} = ['{\color{red}',num2str(kk),'}'];
0511             else
0512                 str_id{end+1} = num2str(num2str(kk));
0513             end
0514         end
0515     end
0516     
0517 end
0518 
0519 
0520 if FLAGS.cell_flag == 1 && isfield( data.regs, 'ID' )
0521     hhh = title('Cell ID');
0522     set(hhh, 'Color', [0,0,0] );
0523     text( xpos_id, ypos_id,str_id,...
0524         'color','w',...
0525         'FontWeight', 'Bold',...
0526         'HorizontalAlignment','Center',...
0527         'VerticalAlignment','Middle',...
0528         'FontSize', 8);
0529 else
0530     hhh = title('Region Number');
0531     set(hhh, 'Color', [0,0,0] );
0532     text( xpos_id, ypos_id,str_id,...
0533         'color','w',...
0534         'HorizontalAlignment','Center',...
0535         'VerticalAlignment','Middle',...
0536         'FontSize', 8);
0537 end
0538 end
0539 
0540 function intPlotSpot( data, x_, y_, FLAGS, ID_LIST, CONST )
0541 % intPlotSpot : plots each foci in the cells
0542 
0543 
0544 if isfield( data, 'CellA' ) && ~isempty( data.CellA ) && ...
0545         (isfield( data.CellA{1}, 'locus1') || (isfield( data.CellA{1}, 'locus2')))
0546     
0547     counter1 = 0;
0548     counter2 = 0;
0549     maxCounter1 = 500;
0550     maxCounter2 = 500;
0551     locus_1_txt = {};
0552     locus1_x = [];
0553     locus1_y = [];
0554     locus_2_txt = {};
0555     locus2_x = [];
0556     locus2_y = [];
0557     for kk = 1:data.regs.num_regs
0558         % only plot spots in the cell that are gated.
0559         if (~FLAGS.cell_flag || ismember(data.regs.ID(kk), ID_LIST))
0560             % locus 1
0561             if isfield( data.CellA{kk}, 'locus1') &&  ( FLAGS.f_flag == 1 );
0562                 num_spot = numel( data.CellA{kk}.locus1);
0563                 mm = 0;
0564                 while mm < num_spot && counter1 < maxCounter1
0565                     mm = mm + 1;
0566                     r = data.CellA{kk}.locus1(mm).r;
0567                     text_ = [num2str(data.CellA{kk}.locus1(mm).score, '%0.1f')];
0568                     if data.CellA{kk}.locus1(mm).score > CONST.getLocusTracks.FLUOR1_MIN_SCORE
0569                         xpos = r(1)+x_;
0570                         ypos = r(2)+y_;
0571                         if (FLAGS.axis(1)<xpos) && (FLAGS.axis(2)>xpos) && ...
0572                                 (FLAGS.axis(3)<ypos) && (FLAGS.axis(4)>ypos)
0573                             counter1 = counter1 + 1;
0574                             locus_1_txt{end+1} = [num2str(data.CellA{kk}.locus1(mm).score, '%0.1f')];
0575                             locus1_x = [locus1_x;xpos];
0576                             locus1_y = [locus1_y;ypos];
0577                         end
0578                     end
0579                 end
0580             end
0581             
0582             % locus 2
0583             if isfield( data.CellA{kk}, 'locus2') && (FLAGS.f_flag == 2 )
0584                 num_spot = numel( data.CellA{kk}.locus2);
0585                 mm = 0;
0586                 while mm < num_spot && counter2 < maxCounter2
0587                     mm = mm + 1;
0588                     r = data.CellA{kk}.locus2(mm).r;
0589                     if data.CellA{kk}.locus2(mm).score > CONST.getLocusTracks.FLUOR2_MIN_SCORE && ...
0590                             data.CellA{kk}.locus2(mm).b < 3
0591                         xpos = r(1)+x_;
0592                         ypos = r(2)+y_;
0593                         if (FLAGS.axis(1)<xpos) && (FLAGS.axis(2)>xpos) && ...
0594                                 (FLAGS.axis(3)<ypos) && (FLAGS.axis(4)>ypos)
0595                             counter2 = counter2 + 1;
0596                             locus_2_txt{end+1} = [num2str(data.CellA{kk}.locus2(mm).score, '%0.1f')];
0597                             locus2_x = [locus2_x;xpos];
0598                             locus2_y = [locus2_y;ypos];
0599                         end
0600                     end
0601                 end
0602             end
0603         end
0604     end
0605     
0606     
0607     text( locus2_x+1, locus2_y, locus_2_txt, 'Color', [1,0.5,0.5]);
0608     plot( locus2_x, locus2_y, '.', 'Color', [1,0.5,0.5]);
0609     
0610     text( locus1_x+1, locus1_y, locus_1_txt, 'Color', [0.5,1,0.5]);
0611     plot( locus1_x, locus1_y, '.', 'Color', [0.5,1,0.5]);
0612     
0613 end
0614 end
0615 
0616 function intPlotLinks( data, data_r, data_f, x_, y_, FLAGS, ID_LIST, CONST )
0617 % intPlotLinks : plots the links to the next and previous frames
0618 
0619 dataHasIds = isfield( data, 'regs' ) && isfield( data.regs,'ID' );
0620 dataRHasIds = ~isempty(data_r) && isfield( data_r, 'regs' ) && isfield( data_r.regs,'ID' );
0621 dataFHasIds = ~isempty(data_f) && isfield( data_f, 'regs' ) && isfield( data_f.regs,'ID' );
0622 
0623 %Plot reverse links
0624 if dataHasIds
0625     colorMap = hsv(10);
0626     
0627     counter = 0;
0628     maxCounter = 500;
0629     
0630     for kk = 1:data.regs.num_regs
0631         % only plot links in the cell that are gated.
0632         if data.regs.ID(kk) ~= 0 && (~FLAGS.cell_flag || ismember(data.regs.ID(kk), ID_LIST))
0633             previousRegion = [];
0634             nextRegion = [];
0635             
0636             if dataRHasIds && data.regs.ID(kk) ~= 0
0637                 previousRegion = find(data_r.regs.ID == data.regs.ID(kk));
0638                 
0639                 if previousRegion == 0
0640                     previousRegion = [];
0641                 end
0642             end
0643             if dataFHasIds && data.regs.ID(kk) ~= 0
0644                 nextRegion = find(data_f.regs.ID == data.regs.ID(kk));
0645                 
0646                 if nextRegion == 0
0647                     nextRegion = [];
0648                 end
0649             end
0650             
0651             color = colorMap(mod(kk, 10) + 1, :);
0652             valid = 0;
0653             
0654             if ~isempty(previousRegion)
0655                 X = [data_r.regs.props(previousRegion).Centroid(1) + x_, data.regs.props(kk).Centroid(1) + x_];
0656                 Y = [data_r.regs.props(previousRegion).Centroid(2) + y_, data.regs.props(kk).Centroid(2) + y_];
0657                 
0658                 plot(X, Y, 'Color', color);
0659                 
0660                 valid = 1;
0661             else
0662                 if data.regs.age(kk) == 1
0663                     motherRegion = [];
0664                     
0665                     if dataRHasIds && data.regs.motherID(kk) ~= 0
0666                         motherRegion = find(data_r.regs.ID == data.regs.motherID(kk));
0667                         
0668                         if motherRegion == 0
0669                             motherRegion = [];
0670                         end
0671                     end
0672                     
0673                     if ~isempty(motherRegion)
0674                         if FLAGS.showMothers == 1
0675                             X = [data_r.regs.props(motherRegion).Centroid(1) + x_, data.regs.props(kk).Centroid(1) + x_];
0676                             Y = [data_r.regs.props(motherRegion).Centroid(2) + y_, data.regs.props(kk).Centroid(2) + y_];
0677                             
0678                             plot(X, Y, 'Color', color);
0679                         end
0680                         
0681                         valid = 1;
0682                     else
0683                         valid = 0;
0684                     end
0685                 end
0686             end
0687             
0688             if ~isempty(nextRegion)
0689                 X = [data_f.regs.props(nextRegion).Centroid(1) + x_, data.regs.props(kk).Centroid(1) + x_];
0690                 Y = [data_f.regs.props(nextRegion).Centroid(2) + y_, data.regs.props(kk).Centroid(2) + y_];
0691                 plot(X, Y, 'Color', color);
0692                 plot(X(1), Y(1), 's', 'Color', color);
0693             else
0694                 if data.regs.deathF(kk)
0695                     daughterRegions = [];
0696                     
0697                     if dataFHasIds && data.regs.ID(kk) ~= 0
0698                         daughterRegions = find(data_f.regs.motherID == data.regs.ID(kk));
0699                         
0700                         if min(daughterRegions) == 0
0701                             daughterRegions = [];
0702                         end
0703                     end
0704                     
0705                     if ~isempty(daughterRegions)
0706                         if FLAGS.showDaughters == 1
0707                             for i = 1:numel(daughterRegions)
0708                                 X = [data_f.regs.props(daughterRegions(i)).Centroid(1) + x_, data.regs.props(kk).Centroid(1) + x_];
0709                                 Y = [data_f.regs.props(daughterRegions(i)).Centroid(2) + y_, data.regs.props(kk).Centroid(2) + y_];
0710                                 
0711                                 plot(X, Y, 'Color', color);
0712                                 plot(X(1), Y(1), 's', 'Color', color);
0713                             end
0714                         end
0715                     else
0716                         valid = 0;
0717                     end
0718                 else
0719                     valid = 0;
0720                 end
0721             end
0722             
0723             X =  data.regs.props(kk).Centroid(1) + x_;
0724             Y =  data.regs.props(kk).Centroid(2) + y_;
0725             if valid == 0
0726                 plot(X, Y, 'x', 'Color', color);
0727             else
0728                 plot(X, Y, 'o', 'Color', color);
0729             end
0730         end
0731         
0732         counter = counter + 1;
0733         if counter >= maxCounter
0734             break;
0735         end
0736     end
0737 end
0738 end
0739 
0740 function intPlotPole( data, x_, y_,FLAGS )
0741 % intPlotPole shows pole positions and connects daughter cells to each other
0742 if ~isfield(data,'CellA')
0743     disp ('Showing poles is not supported in this mode (seg files)');
0744     return;
0745 else
0746     for kk = 1:data.regs.num_regs
0747         
0748         rr1 = data.regs.props(kk).Centroid;
0749         ID  = data.regs.ID(kk);
0750         sisterID = data.regs.sisterID(kk);
0751         
0752         if sisterID
0753             ind = find(data.regs.ID == sisterID);
0754             if numel(ind)>1
0755                 ind = ind(1);
0756             end
0757         else
0758             ind = [];
0759         end
0760         
0761         if isfield( data, 'CellA' )
0762             try
0763                 tmp = data.CellA{kk};
0764                 r = tmp.coord.r_center;
0765                 xaxisx = r(1) + [0,tmp.length(1)*tmp.coord.e1(1)]/2;
0766                 xaxisy = r(2) + [0,tmp.length(1)*tmp.coord.e1(2)]/2;
0767                 yaxisx = r(1) + [0,tmp.length(2)*tmp.coord.e2(1)]/2;
0768                 yaxisy = r(2) + [0,tmp.length(2)*tmp.coord.e2(2)]/2;
0769                 
0770                 if tmp.pole.op_ori
0771                     old_pole = r + tmp.length(1)*tmp.coord.e1*tmp.pole.op_ori/2;
0772                     new_pole = r - tmp.length(1)*tmp.coord.e1*tmp.pole.op_ori/2;
0773                 else
0774                     old_pole = r + tmp.length(1)*tmp.coord.e1/2;
0775                     new_pole = r - tmp.length(1)*tmp.coord.e1/2;
0776                 end
0777             catch ME
0778                 printError(ME);
0779             end
0780             
0781             
0782             if (FLAGS.axis(1)<r(1)) && (FLAGS.axis(2)>r(1)) && ...
0783                     (FLAGS.axis(3)<r(2)) && (FLAGS.axis(4)>r(2))
0784                 
0785                 line = plot([r(1),new_pole(1)], [r(2),new_pole(2)], 'r' );
0786                 
0787                 p_old = plot( old_pole(1)+x_, old_pole(2)+y_, 'ro','MarkerSize',6);
0788                 p_new = plot( new_pole(1)+x_, new_pole(2)+y_, 'r*','MarkerSize',6);
0789                 
0790                 
0791                 if ~isempty(ind) && ID && tmp.pole.op_ori
0792                     if ID < sisterID
0793                         tmps = data.CellA{ind};
0794                         rs = tmps.coord.r_center;
0795                         new_pole_s = rs - tmps.length(1)*tmps.coord.e1*tmps.pole.op_ori/2;
0796                         plot( [new_pole(1),new_pole_s(1)]+x_, [new_pole(2),new_pole_s(2)]+y_, 'w-');
0797                     end
0798                 end
0799             end
0800         end
0801     end
0802     if FLAGS.legend
0803         legend([p_old,p_new,line],{'Old Pole', 'New pole','Sisters'},'location','BestOutside');
0804     end
0805 end
0806 end
0807 
0808 
0809 function [xx,yy] = intGetImSize( data, FLAGS )
0810 % intGetImSize : gets size of regions labels  and fills up xx and yy
0811 % from 1 to the size of the image.
0812 
0813 
0814 if isfield( data, 'regs' )
0815     ss = size(data.regs.regs_label);
0816     
0817     if FLAGS.T_flag % tight flag
0818         tmp_props = regionprops( data.regs.regs_label, 'BoundingBox' );
0819         pad = 10;
0820         
0821         yymin_ = ceil(tmp_props(1).BoundingBox(2))-pad;
0822         yymax_ = yymin_ + ceil(tmp_props(1).BoundingBox(4))-1+2*pad;
0823         xxmin_ = ceil(tmp_props(1).BoundingBox(1))-pad;
0824         xxmax_ = xxmin_ + ceil(tmp_props(1).BoundingBox(3))-1+2*pad;
0825         
0826         num_segs = max(data.regs.regs_label(:));
0827         
0828         for ii = 2:num_segs
0829             yymin = ceil(tmp_props(ii).BoundingBox(2))-pad;
0830             yymax = yymin + ceil(tmp_props(ii).BoundingBox(4))-1+2*pad;
0831             xxmin = ceil(tmp_props(ii).BoundingBox(1))-pad;
0832             xxmax = xxmin + ceil(tmp_props(ii).BoundingBox(3))-1+2*pad;
0833             
0834             yymin_ = min( [yymin_, yymin] );
0835             yymax_ = max( [yymax_, yymax] );
0836             xxmin_ = min( [xxmin_, xxmin] );
0837             xxmax_ = max( [xxmax_, xxmax] );
0838         end
0839         yy = max([1,yymin_]):min([ss(1),yymax_]);
0840         xx = max([1,xxmin_]):min([ss(2),xxmax_]);
0841     else
0842         xx = 1:ss(2);
0843         yy = 1:ss(1);
0844     end
0845 else
0846     ss = size(data.phase);
0847     xx = 1:ss(2);
0848     yy = 1:ss(1);
0849 end
0850 end
0851 
0852 function FLAGS = intFixFlags( FLAGS )
0853 % intFixFlags :  sets default flag values if the value is missing.
0854 % Outline_flag
0855 % ID_flag
0856 % lyse_flag
0857 % m_flag
0858 % c_flag
0859 
0860 if ~isfield(FLAGS, 'legend');
0861     disp('there is no flag field legend');
0862     FLAGS.legend = 1;
0863 end
0864 
0865 if ~isfield(FLAGS, 'Outline_flag');
0866     disp('there is no flag field Outline_flag');
0867     FLAGS.Outline_flag = 0;
0868 end
0869 if ~isfield(FLAGS, 'ID_flag');
0870     disp('there is no flag field ID_flag');
0871     FLAGS.ID_flag = 1;
0872 end
0873 
0874 if ~isfield(FLAGS, 'lyse_flag');
0875     disp('there is no flag field lyse_flag')
0876     FLAGS.lyse_flag = 0;
0877 end
0878 
0879 if ~isfield(FLAGS,'m_flag');
0880     disp('there is no flag field m_flag')
0881     FLAGS.m_flag = 0;
0882 end
0883 
0884 if ~isfield(FLAGS, 'c_flag');
0885     disp('there is no flag field c_flag')
0886     FLAGS.c_flag = 0;
0887 end
0888 
0889 if ~isfield(FLAGS, 'P_flag');
0890     disp('there is no flag field P_flag')
0891     FLAGS.P_flag = 1;
0892 end
0893 
0894 
0895 if ~isfield(FLAGS, 'phase_flag');
0896     disp('there is no flag field P_flag')
0897     FLAGS.phase_flag = 1;
0898 end
0899 
0900 if ~isfield(FLAGS, 'phase_level');
0901     disp('there is no flag field P_flag')
0902     FLAGS.phase_level = 1;
0903 end
0904 
0905 if ~isfield(FLAGS, 'cell_flag' );
0906     disp('there is no flag field cell_flag')
0907     FLAGS.cell_flag = 0;
0908 end
0909 
0910 if ~isfield(FLAGS, 'f_flag');
0911     disp('there is no flag field f_flag')
0912     FLAGS.f_flag = 0;
0913 end
0914 
0915 if ~isfield(FLAGS, 's_flag');
0916     disp('there is no flag field s_flag')
0917     FLAGS.s_flag = 0;
0918 end
0919 
0920 if ~isfield(FLAGS, 'T_flag');
0921     disp('there is no flag field T_flag')
0922     FLAGS.T_flag = 0;
0923 end
0924 
0925 if ~isfield(FLAGS, 'filt')
0926     disp('there is not field filt_flag')
0927     FLAGS.filt = [0,0,0];
0928 end
0929 
0930 if ~isfield(FLAGS, 'p_flag');
0931     disp('there is not field p_flag')
0932     FLAGS.p_flag = 0;
0933 end
0934 
0935 if ~isfield(FLAGS,'composite')
0936     disp('there is not field composite')
0937     FLAGS.composite  = 0;
0938 end
0939 
0940 
0941 if ~isfield(FLAGS, 'showLinks');
0942     disp('there is not field showLinks')
0943     FLAGS.showLinks = 0;
0944 end
0945 
0946 FLAGS.link_flag = FLAGS.s_flag || FLAGS.ID_flag;
0947 
0948 end
0949 
0950 function outline = intDoOutline( map )
0951 persistent sqrStrel;
0952 if isempty( sqrStrel );
0953     sqrStrel = strel('square',3);
0954 end
0955 outline = 2*double(imdilate( map, sqrStrel ))-double(map);
0956 end
0957 
0958 
0959 function outline = intDoOutline2( map )
0960 persistent sqrStrel;
0961 if isempty( sqrStrel );
0962     sqrStrel = strel('square',3);
0963 end
0964 outline = double(imdilate( map, sqrStrel ))-double(map);
0965 end

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