Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
avoided saving tiff files, now a mat file is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-vollrathf committed Aug 11, 2016
1 parent d14b044 commit 4696e1d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CellsortApplyFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions CellsortChoosePCs.m
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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];
Expand Down
16 changes: 7 additions & 9 deletions CellsortPCA.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -324,6 +322,6 @@
%
% Modified April 9, 2013 for compatibility with MATLAB 2012b

j = length(imfinfo(fn));
j = size(data_g,3);
end
end
6 changes: 3 additions & 3 deletions CellsortPlotPCspectrum.m
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
26 changes: 15 additions & 11 deletions main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 4696e1d

Please sign in to comment.