-
Notifications
You must be signed in to change notification settings - Fork 0
/
JENI.m
128 lines (116 loc) · 4.72 KB
/
JENI.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
% Process a journal.
%
% [InputFolder MaskFolder] = JENI(Journal,ForceInputFolder,ForceOutputFolder);
%
% Journal can be the absolute path to a journal or a path (starting by './') relative to LOBSTER_ROOT
%
% - For no input argument, a journal can be selected from a file browser
% - ForceInputFolder redirects journal input folder
% - ForceOutputFolder redirects journal output folder (required if ForceInputFolder is set, but can be set to '')
% - ForceChan (ForceInputFolder and ForceOutputFolder can be both set to '' to use it)
% Sample calls:
% JENI;
% JENI('NucleiCytoo_GradWaterTilesMerge.jl');
% [InputFolder OutputFolder] = JENI('NucleiCytoo_GradWaterTilesMerge.jl');
% [InputFolder MaskFolder] = JENI('BloodVessels3D_LocThr3D.jls','E:/LOBSTER_sandbox/Images/BloodVessels3D','E:/LOBSTER_sandbox/Images/BloodVessels3D_o1');
% [InputFolder MaskFolder] = JENI('BloodVessels3D_LocThr3D.jls','E:/LOBSTER_sandbox/Images/BloodVessels3D',1);
function [InputFolder OutputFolder] = JENI(Journal,ForceInputFolder,ForceOutputFolder,ForceChan)
%% Check that imtool3D is in path (init has been performed)
if ~exist('imtool3D')
error('LOBSTER has not been initialized yet, type >> init');
else
%% Force path to LOBSTER root on startup
str = which('init');
indxs = find((str=='/')|(str=='\'));
cd(str(1:indxs(end)));
end
%% Check number of input arguments
if nargin == 2 || nargin > 4
error('Incorrect call to JENI: 0, 1, 3 or 4 input arguments');
end
%% Set/fix forced folder paths
if nargin > 1
if ~isempty(ForceInputFolder)
ForceInputFolder = FixFolderPath(ForceInputFolder);
end
if isnumeric(ForceOutputFolder)
fields = strsplit(ForceInputFolder,{'/','\'});
if ForceOutputFolder > 0
%% Single folder back (files in input folder)
ForceOutputFolder = [ForceInputFolder '../' fields{end-1} '_o' num2str(ForceOutputFolder) '/'];
else
%% Two folder back (folders in input folder)
ForceOutputFolder = [ForceInputFolder '../../' fields{end-2} '_o' num2str(abs(ForceOutputFolder)) '/' fields{end-1} '/'];
end
end
if ~isempty(ForceInputFolder)
ForceInputFolder = GetFullPath(ForceInputFolder);
end
if ~isempty(ForceOutputFolder)
ForceOutputFolder = GetFullPath(ForceOutputFolder);
end
end
%% Check if JENI was called from JULI
callers = dbstack;
callers = {callers.name};
JULIcall = any(strcmp(callers,'JULI'));
if ~JULIcall
%% File explorer if no journal file is passed
if nargin == 0
JournalPath = [pwd '/Journals/'];
[Journal, JournalPath] = uigetfile([JournalPath '*.*'],'Select journal to run');
Journal = [JournalPath Journal];
end
else
if nargin == 0
error('Journal file must be defined when calling from JULI');
end
end
%% Initialization
clearvars -except 'Journal' 'ForceInputFolder' 'ForceOutputFolder' 'ForceChan';
close all;
warning on;
%% Parse file name
fsep = find((Journal=='/')|(Journal=='\'));
[filepath, name, ext] = fileparts(Journal);
%% Check journal extension and set default path if journal has no path
if isempty(fsep)
switch ext
case '.jl'
Journal = [pwd '/Journals/jl/' Journal];
case '.jls'
Journal = [pwd '/Journals/jls/' Journal];
case '.jlm'
Journal = [pwd '/Journals/jlm/' Journal];
otherwise
error('Invalid journal extension');
end
end
%% Process journal
switch ext
case '.jl'
if nargin <2
[InputFolder, OutputFolder] = JENI_Images(Journal);
else
if nargin == 3
[InputFolder, OutputFolder] = JENI_Images(Journal,ForceInputFolder,ForceOutputFolder);
else
[InputFolder, OutputFolder] = JENI_Images(Journal,ForceInputFolder,ForceOutputFolder,ForceChan);
end
end
case '.jls'
if nargin <2
[InputFolder, OutputFolder] = JENI_Stacks(Journal);
else
[InputFolder, OutputFolder] = JENI_Stacks(Journal,ForceInputFolder,ForceOutputFolder);
end
case '.jlm'
if nargin <2
[InputFolder, OutputFolder] = JENI_Movie(Journal);
else
[InputFolder, OutputFolder] = JENI_Movie(Journal,ForceInputFolder,ForceOutputFolder);
end
otherwise
error('Invalid journal extension');
end
end