From 4696e1da50aede4642e2f3e449ca5c7c34e140dc Mon Sep 17 00:00:00 2001 From: Florian Vollrath Date: Thu, 11 Aug 2016 15:20:49 +0200 Subject: [PATCH] avoided saving tiff files, now a mat file is saved --- CellsortApplyFilter.m | 2 +- CellsortChoosePCs.m | 4 ++-- CellsortPCA.m | 16 +++++++--------- CellsortPlotPCspectrum.m | 6 +++--- main.m | 26 +++++++++++++++----------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/CellsortApplyFilter.m b/CellsortApplyFilter.m index bf7444b..13663d1 100644 --- a/CellsortApplyFilter.m +++ b/CellsortApplyFilter.m @@ -21,7 +21,7 @@ % if (nargin<3)||isempty(flims) - nt = tiff_frames(fn); + nt = size(data_g, 3)%tiff_frames(fn); flims = [1,nt]; else nt = diff(flims)+1; diff --git a/CellsortChoosePCs.m b/CellsortChoosePCs.m index 44606b3..04e99d7 100644 --- a/CellsortChoosePCs.m +++ b/CellsortChoosePCs.m @@ -1,4 +1,4 @@ -function [PCuse] = CellsortChoosePCs(fn, mixedfilters) +function [PCuse] = CellsortChoosePCs(fn, mixedfilters, data_g) % [PCuse] = CellsortChoosePCs(fn, mixedfilters) % % Allows the user to select which principal components will be kept @@ -19,7 +19,7 @@ fprintf('-------------- CellsortChoosePCs %s -------------- \n', date) -[pixw,pixh] = size(imread(fn,1)); +[pixw,pixh] = size(data_g(:,:,1)); npcs = 20; % Number of PCs to display concurrently currpcs = [1:npcs]; diff --git a/CellsortPCA.m b/CellsortPCA.m index c8ab5b3..81e5518 100644 --- a/CellsortPCA.m +++ b/CellsortPCA.m @@ -46,11 +46,9 @@ %----------------------- % Check inputs -if isempty(dir(fn)) - error('Invalid input file name.') -end +numFrames = size(data_g,3); if (nargin<2)||(isempty(flims)) - nt_full = tiff_frames(fn); + nt_full = numFrames; flims = [1,nt_full]; end @@ -103,7 +101,7 @@ fncovmat = [outputdir, fname, '_cov_', num2str(flims(1)), ',', num2str(flims(2)), '_', date,'.mat']; -[pixw,pixh] = size(imread(fn,1)); +[pixw,pixh] = size(data_g(:,:,1)); npix = pixw*pixh; fprintf(' %d pixels x %d time frames;', npix, nt) @@ -138,7 +136,7 @@ end mixedfilters = reshape(mixedfilters, pixw,pixh,nPCs); -firstframe_full = imread(fn,1); +firstframe_full = data_g(:,:,1);%imread(fn,1); firstframe = firstframe_full; if dsamp_space>1 firstframe = imresize(firstframe, size(mov(:,:,1)),'bilinear'); @@ -177,7 +175,7 @@ end end else - [pixw_dsamp,pixh_dsamp] = size(imresize( imread(fn,1), 1/dsamp_space, 'bilinear' )); + [pixw_dsamp,pixh_dsamp] = size(imresize( data_g(:,:,1), 1/dsamp_space, 'bilinear' )); npix = pixw_dsamp*pixh_dsamp; mov = zeros(pixw_dsamp, pixh_dsamp, nt); for jjind=1:length(useframes) @@ -239,7 +237,7 @@ end end else - [pixw_dsamp,pixh_dsamp] = size(imresize( imread(fn,1), 1/dsamp_space, 'bilinear' )); + [pixw_dsamp,pixh_dsamp] = size(imresize( data_g(:,:,1), 1/dsamp_space, 'bilinear' )); npix = pixw_dsamp*pixh_dsamp; mov = zeros(pixw_dsamp, pixh_dsamp, nt); for jjind=1:length(useframes) @@ -324,6 +322,6 @@ % % Modified April 9, 2013 for compatibility with MATLAB 2012b - j = length(imfinfo(fn)); + j = size(data_g,3); end end diff --git a/CellsortPlotPCspectrum.m b/CellsortPlotPCspectrum.m index a7e362a..eea69e6 100644 --- a/CellsortPlotPCspectrum.m +++ b/CellsortPlotPCspectrum.m @@ -1,4 +1,4 @@ -function CellsortPlotPCspectrum(fn, CovEvals, PCuse) +function CellsortPlotPCspectrum(fn, CovEvals, PCuse, data_g) % CellsortPlotPCspectrum(fn, CovEvals, PCuse) % % Plot the principal component (PC) spectrum and compare with the @@ -18,9 +18,9 @@ function CellsortPlotPCspectrum(fn, CovEvals, PCuse) PCuse = []; end -[pixw,pixh] = size(imread(fn,1)); +[pixw,pixh] = size(data_g(:,:,1)); npix = pixw*pixh; -nt = tiff_frames(fn); +nt = size(data_g,3); % Random matrix prediction (Sengupta & Mitra) p1 = npix; % Number of pixels diff --git a/main.m b/main.m index e80d490..bdc9643 100644 --- a/main.m +++ b/main.m @@ -16,16 +16,20 @@ binningFactor = [1 1 2]; %x, y, t [data_g, data_r] = CellSortTemporalBinning(data_g, data_r, binningFactor); -fn_green = 'green.tiff'; -fn_red = 'red.tiff'; -CellSortExportTifStack(data_g, fn_green); -CellSortExportTifStack(data_r, fn_red); +fn = 'processedData.mat'; +save(fn, 'data_g', 'data_r', '-v7.3'); +% fn_green = 'green.tiff'; +% fn_red = 'red.tiff'; +% CellSortExportTifStack(data_g, fn_green); +% CellSortExportTifStack(data_r, fn_red); %% load files %if you haven't used the shiftCorrection you have to load the already processed files -fn_green = 'green.tiff'; -fn_red = 'red.tiff'; -data_g = readTiff(fn_green); -data_r = readTiff(fn_red); +fn_green = 'processedData.mat'; +load(fn); +% fn_green = 'green.tiff'; +% fn_red = 'red.tiff'; +% data_g = readTiff(fn_green); +% data_r = readTiff(fn_red); %% 1. PCA %calculate PCAs nPCs = 100; @@ -37,11 +41,11 @@ %% 2a. Choose PCs %choose PCAs, type f/b in command line to go back or forward. type two number %to select the range "1 ENTER 25 ENTER" would select the PCAs from 1 to 25 -[PCuse] = CellsortChoosePCs(fn_green, mixedfilters); +[PCuse] = CellsortChoosePCs(fn_green, mixedfilters, data_g); %% 2b. Plot PC spectrum %optionally, you can display the PC spectrum.. -CellsortPlotPCspectrum(fn_green, CovEvals, PCuse) +CellsortPlotPCspectrum(fn_green, CovEvals, PCuse, data_g) %% 3a. ICA %calculate ICAs, set mu to a value between 0 and 1, where 1 means pure @@ -60,7 +64,7 @@ dt = 0.1; figure(2) -CellsortICAplot('series', ica_filters, ica_sig, movm, tlims, dt, [], [], [1:size(ica_segments,1)]); +CellsortICAplot('series', ica_filters, ica_sig, movm, tlims, dt, [], [], [1:size(ica_sig,1)]); %% 4a. Segment contiguous regions within ICs %search for indepent segments, you have to adjust these values well: