-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractCellposeSettings.java
More file actions
155 lines (125 loc) · 3.29 KB
/
AbstractCellposeSettings.java
File metadata and controls
155 lines (125 loc) · 3.29 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
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
152
153
154
155
package fiji.plugin.trackmate.cellpose;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import ij.IJ;
public abstract class AbstractCellposeSettings
{
/**
* Interface for enums that represent a pretrained or a custom model in
* cellpose or omnipose.
*/
public interface PretrainedModel
{
/**
* Returns <code>true</code> if this model is a custom model.
*
* @return <code>true</code> if this model is a custom model.
*/
boolean isCustom();
/**
* Returns the name of this pretrained model, or its path if it is a
* custom model.
*
* @return the model name or path.
*/
String getPath();
}
public final String executablePath;
public final int chan;
public final int chan2;
public final String customModelPath;
public final double diameter;
public final boolean useGPU;
public final boolean simplifyContours;
private final PretrainedModel model;
protected AbstractCellposeSettings(
final String executablePath,
final PretrainedModel model,
final String customModelPath,
final int chan,
final int chan2,
final double diameter,
final boolean useGPU,
final boolean simplifyContours )
{
this.executablePath = executablePath;
this.model = model;
this.chan = chan;
this.chan2 = chan2;
this.customModelPath = customModelPath;
this.diameter = diameter;
this.useGPU = useGPU;
this.simplifyContours = simplifyContours;
}
/**
* Returns the executable name of the cellpose or omnipose command. For
* cellpose, it's simply 'cellpose'.
*
* @return the executable name.
*/
public abstract String getExecutableName();
public List< String > toCmdLine( final String imagesDir )
{
final List< String > cmd = new ArrayList<>();
/*
* First decide whether we are calling Cellpose from python, or directly
* the Cellpose executable. We check the last part of the path to check
* whether this is python or cellpose.
*/
final String[] split = executablePath.replace( "\\", "/" ).split( "/" );
final String lastItem = split[ split.length - 1 ];
if ( lastItem.toLowerCase().startsWith( "python" ) )
{
// Activate conda env if it runs in Windows.
if ( IJ.isWindows() )
{
final String envname = split[ split.length - 2 ];
cmd.addAll( Arrays.asList( "cmd.exe", "/c", "conda", "activate", envname ) );
cmd.add( "&" );
}
// Calling Cellpose from python.
cmd.add( executablePath );
cmd.add( "-m" );
cmd.add( getExecutableName() );
}
else
{
// Calling Cellpose executable.
cmd.add( executablePath );
}
/*
* Cellpose command line arguments.
*/
// Target dir.
cmd.add( "--dir" );
cmd.add( imagesDir );
// First channel.
cmd.add( "--chan" );
cmd.add( "" + chan );
// Second channel.
if ( chan2 >= 0 )
{
cmd.add( "--chan2" );
cmd.add( "" + chan2 );
}
// GPU.
if ( useGPU )
cmd.add( "--use_gpu" );
// Diameter.
cmd.add( "--diameter" );
cmd.add( ( diameter > 0 ) ? "" + diameter : "0" );
// Model.
cmd.add( "--pretrained_model" );
if ( model.isCustom() )
cmd.add( customModelPath );
else
cmd.add( model.getPath() );
// Export results as PNG.
cmd.add( "--save_png" );
// Do not save Numpy files.
cmd.add( "--no_npy" );
return Collections.unmodifiableList( cmd );
}
}