-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsaLoadStack.m
53 lines (49 loc) · 1.68 KB
/
saLoadStack.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function tStack = saLoadStack()
% Load images from previously saved results file, if it exists.
% Otherwise, load images direcly from current directory.
%
% Usage:
% tStack = saLoadStack()
%
% Image files must use the following naming convention:
% Animal_Region_Slide_Section_Stain.tiff
%
% Example:
% CX34_BS_1_08_Nissl.tiff
%
% The imaged tissue should be in the same orientation across all images,
% i.e. anatomical axes relative to image axes should be the same.
%
%
sResultsFile = 'sa_image_stack.mat';
if exist(sResultsFile, 'file')
disp('saLoadStack: Loading stack from disk...')
load(sResultsFile)
fprintf('saLoadStack: Loaded %s \n', [pwd filesep sResultsFile])
else
% Get list of images
tDir = dir('*.tiff');
tStack = struct([]);
fprintf('saLoadStack: Loading %d images...\n', numel(tDir));
for f = 1:length(tDir)
sName = tDir(f).name;
fprintf ('Loading image %d / %d \r', f, numel(tDir))
% Filename format
% Mouse_Region_Slide_Section_Stain.tiff
% Example: CX34_BS_1_08_Nissl.tiff
try
cValues = textscan(sName(1:end-5), '%s%s%f%f%s', 'delimiter', '_');
tStack(end+1).sAnimal = cell2mat(cValues{1});
tStack(end).sRegion = cell2mat(cValues{2});
tStack(end).nSlide = cValues{3};
tStack(end).nSection = cValues{4};
tStack(end).sStain = cell2mat(cValues{5});
catch
error('Failed parsing filename in saLoadStack(). Check that all filenames have the correct format.')
end
% Load images
tStack(end).mImg = imread(sName);
end
fprintf('\nsaLoadStack: Done reading %d images.\n', f)
end
return