CellSort 1.0 > CellsortApplyFilter.m

CellsortApplyFilter

PURPOSE ^

cell_sig = CellsortApplyFilter(fn, ica_segments, flims, movm, subtractmean)

SYNOPSIS ^

function cell_sig = CellsortApplyFilter(fn, ica_segments, flims, movm, subtractmean)

DESCRIPTION ^

 cell_sig = CellsortApplyFilter(fn, ica_segments, flims, movm, subtractmean)

CellsortApplyFilter
 Read in movie data and output signals corresponding to specified spatial
 filters

 Inputs:
     fn - file name of TIFF movie file
     ica_segments - nIC x X matrix of ICA spatial filters
     flims - optional two-element vector of frame limits to be read
     movm - mean fluorescence image
     subtractmean - boolean specifying whether or not to subtract the mean
     fluorescence of each time frame

 Outputs:
     cell_sig - cellular signals

 Eran Mukamel, Axel Nimmerjahn and Mark Schnitzer, 2009
 Email: eran@post.harvard.edu, mschnitz@stanford.edu

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function cell_sig = CellsortApplyFilter(fn, ica_segments, flims, movm, subtractmean)
0002 % cell_sig = CellsortApplyFilter(fn, ica_segments, flims, movm, subtractmean)
0003 %
0004 %CellsortApplyFilter
0005 % Read in movie data and output signals corresponding to specified spatial
0006 % filters
0007 %
0008 % Inputs:
0009 %     fn - file name of TIFF movie file
0010 %     ica_segments - nIC x X matrix of ICA spatial filters
0011 %     flims - optional two-element vector of frame limits to be read
0012 %     movm - mean fluorescence image
0013 %     subtractmean - boolean specifying whether or not to subtract the mean
0014 %     fluorescence of each time frame
0015 %
0016 % Outputs:
0017 %     cell_sig - cellular signals
0018 %
0019 % Eran Mukamel, Axel Nimmerjahn and Mark Schnitzer, 2009
0020 % Email: eran@post.harvard.edu, mschnitz@stanford.edu
0021 
0022 if (nargin<3)||isempty(flims)
0023     nt = tiff_frames(fn);
0024     flims = [1,nt];
0025 else
0026     nt = diff(flims)+1;
0027 end
0028 if nargin<5
0029     subtractmean = 1;
0030 end
0031 
0032 [pixw,pixh] = size(imread(fn,1));
0033 if (nargin<4)||isempty(movm)
0034     movm = ones(pixw,pixh);
0035 else
0036     movm = double(movm);
0037 end
0038 movm(movm==0) = 1; % Just in case there are black areas in the average image
0039 k=0;
0040 
0041 cell_sig = zeros(size(ica_segments,1), nt);
0042 ica_segments = reshape(ica_segments, [], pixw*pixh);
0043 
0044 fprintf('Loading %5g frames for %d ROIs.\n', nt, size(ica_segments,1))
0045 while k<nt
0046     ntcurr = min(500, nt-k);
0047     mov = zeros(pixw, pixh, ntcurr);
0048     for j=1:ntcurr
0049         movcurr = imread(fn, j+k+flims(1)-1);
0050         mov(:,:,j) = movcurr;
0051     end
0052     mov = (mov ./ repmat(movm, [1,1,ntcurr])) - 1; % Normalize by background and subtract mean
0053 
0054     if subtractmean
0055         % Subtract the mean of each frame
0056         movtm = mean(mean(mov,1),2);
0057         mov = mov - repmat(movtm,[pixw,pixh,1]);
0058     end
0059 
0060     mov = reshape(mov, pixw*pixh, ntcurr);
0061     cell_sig(:, k+[1:ntcurr]) = ica_segments*mov;
0062 
0063     k=k+ntcurr;
0064     fprintf('Loaded %3.0f frames; ', k)
0065     toc
0066 end
0067 
0068 function j = tiff_frames(fn)
0069 %
0070 % n = tiff_frames(filename)
0071 %
0072 % Returns the number of slices in a TIFF stack.
0073 %
0074 %
0075 
0076 status = 1; j=0;
0077 jstep = 10^3;
0078 while status
0079     try
0080         j=j+jstep;
0081         imread(fn,j);
0082     catch
0083         if jstep>1
0084             j=j-jstep;
0085             jstep = jstep/10;
0086         else
0087             j=j-1;
0088             status = 0;
0089         end
0090     end
0091 end

Generated on Wed 29-Jul-2009 12:46:53 by m2html © 2003