-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefineStackNames.m
More file actions
75 lines (62 loc) · 1.96 KB
/
defineStackNames.m
File metadata and controls
75 lines (62 loc) · 1.96 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function [outputFileList]=defineStackNames(firstfilename)
%
% SYNOPSIS [outputFileList]=defineStackNames(firstFileName)
%
% INPUT firstFileName: name of the first greyvalue image to be read
% including the full path
% the actual filename must consist of
% - alphanumeric body
% - numeric number
% - extension
%
% OUTPUT outputFileList: names of all files belonging to the stack
% defined by firstFileName
oldDir = [];
% Output
outputFileList = {};
[fpath,fname,fno,fext]=getFilenameBody(firstfilename);
if(isempty(fname) | isempty(fno) | isempty(fext) )
error('invalid first filename specified');
end;
if(~isempty(fpath))
% change to stack directory
oldDir = cd(fpath);
else
%check if it is in the matlab search path
tempName=which(firstfilename);
if(~isempty(tempName))
[fpath,fname,fno,fext]=getfilenamebody(tempName);
oldDir = cd(fpath);
end;
end;
dirListing = dir;
% get all relevant filenames
iEntry = 1;
fileList = {};
for( i = 1:length(dirListing))
if(~dirListing(i).isdir)
fileList(iEntry) = lower({dirListing(i).name});
iEntry = iEntry + 1;
end;
end;
nEntries = 0;
imIndx = str2num(fno);
l_fno=length(num2str(fno));
searchName= [fname,num2str(imIndx,['%.' num2str(l_fno) 'd']),fext];
%
outputFileList(1)={strcat(fpath,'\',searchName)};
if(~isempty(fileList))
while( ~isempty(strmatch(lower(searchName),fileList)))
nEntries = nEntries + 1;
index(nEntries) = imIndx;
imIndx = imIndx + 1;
searchName= [fname,num2str(imIndx,['%.' num2str(l_fno) 'd']),fext];
outputFileList(imIndx)={strcat(fpath,'\',searchName)};
end;
end;
% Removing last file name, which does not exist
outputFileList=outputFileList(1,1:length(outputFileList)-1);
% change back to original directory
if(~isempty(oldDir))
cd(oldDir);
end;