-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimg2shapespace.m
151 lines (133 loc) · 5.07 KB
/
img2shapespace.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function answer = img2shapespace(varargin)
% img2shapespace.m
%
% Train 3D generative SPHARM-RPDM cell shape model and creates a report
% using the trained model.
%
% Input
% -----
% * a directory of raw or synthetic cell shape images (cell shapes file
% format 'LAM_cell[1-9]_ch1_t1.tif') or OME.TIFFs
% * an options structure to override default options
% see http://www.cellorganizer.org/docs/2.9.0/chapters/cellorganizer_options.html#img2slml
% important options include
% .model.name for name of the model itself
% .model.filename for name of the file in which to store the model
% .model.resolution for setting image/model pixel size
% .downsampling for setting downsampling before model building
% .shape_evolution for setting whether report includes example
% shape evolution
%
% Output
% ------
% * a valid SLML model file
% * a report with an embedded shape space
% Soham Chakraborti ([email protected])
% R.F. Murphy ([email protected])
%
% Copyright (C) 2020 Murphy Lab
% Computational Biology Department
% School of Computer Science
% Carnegie Mellon University
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation; either version 2 of the License,
% or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
% 02110-1301, USA.
%
% For additional information visit http://murphylab.cbd.cmu.edu or
% send email to [email protected]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isdeployed()
filename = is_deployed(varargin{1});
load(filename);
else
if nargin == 2
dnaImagesDirectoryPath = varargin{1};
cellImagesDirectoryPath = varargin{2};
options = struct([]);
else
dnaImagesDirectoryPath = varargin{1};
cellImagesDirectoryPath = varargin{2};
options = varargin{3};
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% img2slml %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
defaultoptions = struct();
defaultoptions.verbose = false;
defaultoptions.debug = false;
defaultoptions.display = false;
defaultoptions.model.id = uuidgen();
%is this needed? what does it do?
defaultoptions.train = struct( 'flag', 'cell' );
defaultoptions.cell.class = 'cell_membrane';
defaultoptions.cell.type = 'spharm_rpdm';
defaultoptions.labels = 'unique';
options = ml_initparam( options, defaultoptions);
if ~isfield(options,'model.filename')
options.model.filename = [options.model.name '.mat'];
end
if ~isfield(options,'model.resolution')
disp ('No resolution specified for the input images;')
disp ('Using default of [0.1, 0.1, 0.1]');
% this is the resolution of the input image
options.model.resolution = [0.1, 0.1, 0.1];
end
if ~isfield(options,'downsampling')
disp ('No downsampling specified prior to model creation;')
disp ('Using default of no downsampling');
options.downsampling = [1, 1, 1];
end
% postprocess of parameterization: alignment
options.model.spharm_rpdm.postprocess = ~false;
% alignment method: 'major_axis' or 'foe'
options.model.spharm_rpdm.alignment_method = 'major_axis';
% plane of rotation: 'xy', 'xz', 'yz' or 'xyz'
options.model.spharm_rpdm.rotation_plane = 'xy';
% degree of the descriptor
options.model.spharm_rpdm.maxDeg = 31;
% latent dimension for the model
options.model.spharm_rpdm.latent_dim = 15;
options.model.spharm_rpdm.segmindnaImagesDirectoryPathfraction = 0.1;
if exist(dnaImagesDirectoryPath,'var') && ~isempty(dnaImagesDirectoryPath)
options.model.name = 'SPHARM-RPDM-NucCellShapeModel';
options.dnaImagesDirectoryPathleus.class = 'nuc_membrane';
options.dnaImagesDirectoryPathleus.type = 'spharm_rpdm';
options.model.spharm_rpdm.components = {'nuc', 'cell'};
else
options.model.spharm_rpdm.components = {'cell'};
options.model.name = 'SPHARM-RPDM-CellShapeModel';
end
tic; answer = img2slml( '3D', dnaImagesDirectoryPath, ...
cellImagesDirectoryPath, [], options ); toc,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if exist( [pwd filesep options.model.filename] )
answer = slml2info( {[pwd filesep options.model.filename]}, options );
if exist( ['./' options.model.name '-report'])
rmdir(['./' options.model.name '-report'],'s')
end
try
movefile( './report' , ['./' options.model.name '-report']);
web(['./' options.model.name '-report' filesep 'index.html'])
catch
disp('Couldn''t rename report folder and open report in browser');
end
else
disp ('Failed to find the model file. Exiting application.' );
answer = false;
end
if isdeployed
close all
end
end%img2shapespace