Skip to content

Commit b91697f

Browse files
committed
Automatically export GT to CTC file format if provided as TrackMate file.
If the GT is provided as a TrackMate file, we need to export it to CTC file format to properly use the CTC metrics. This commit does that but checks first if an existing CTC folder is found in the GT folder.
1 parent c142afa commit b91697f

1 file changed

Lines changed: 43 additions & 5 deletions

File tree

src/main/java/fiji/plugin/trackmate/helper/ctc/CTCMetricsRunner.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -28,6 +28,9 @@
2828
import java.nio.file.Paths;
2929
import java.nio.file.SimpleFileVisitor;
3030
import java.nio.file.attribute.BasicFileAttributes;
31+
import java.util.Optional;
32+
import java.util.regex.Pattern;
33+
import java.util.stream.Stream;
3134

3235
import org.scijava.Context;
3336

@@ -40,7 +43,7 @@
4043
/**
4144
* Performs tracking and all the CTC metrics measurements with a TrackMate
4245
* instance.
43-
*
46+
*
4447
* @author Jean-Yves Tinevez
4548
*/
4649
public class CTCMetricsRunner extends MetricsRunner
@@ -54,7 +57,7 @@ public class CTCMetricsRunner extends MetricsRunner
5457
/**
5558
* Path to ground truth folder.
5659
*/
57-
private final String gtPath;
60+
private String gtPath;
5861

5962
public CTCMetricsRunner( final String gtPath, final String saveFolder, final Context context )
6063
{
@@ -67,8 +70,43 @@ public CTCMetricsRunner( final String gtPath, final String saveFolder, final Con
6770
@Override
6871
public TrackingMetrics performMetricsMeasurements( final TrackMate trackmate ) throws MetricsComputationErrorException
6972
{
70-
batchLogger.log( "Exporting as CTC results.\n" );
73+
// Do we have a folder for the ground-truth, or a TrackMate file?
74+
if ( gtPath.toLowerCase().endsWith( ".xml" ) )
75+
{
76+
// Assume it's a TrackMate file, export it to CTC file format.
77+
batchLogger.log( "Ground-truth is in the TrackMate file format.\n" );
78+
79+
final String regexPattern = "\\d{2}_GT";
80+
final Pattern pattern = Pattern.compile( regexPattern );
81+
try (Stream< Path > paths = Files.list( resultsRootPath ))
82+
{
83+
final Optional< Path > ctcGTfolder = paths
84+
.filter( Files::isDirectory )
85+
.filter( path -> pattern.matcher( path.getFileName().toString() ).matches() )
86+
.findFirst();
87+
88+
if ( ctcGTfolder.isPresent() )
89+
{
90+
batchLogger.log( "Found a GT folder in CTC format: " + ctcGTfolder.get() + "\n" );
91+
gtPath = ctcGTfolder.get().toString();
92+
}
93+
else
94+
{
95+
batchLogger.log( "Exporting GT file to CTC format.\n" );
96+
gtPath = CTCExporter.exportAll( resultsRootPath.toString(), trackmate, ExportType.GOLD_TRUTH, batchLogger );
97+
gtPath = Paths.get( gtPath ).getParent().toString();
98+
}
99+
}
100+
catch ( final IOException e )
101+
{
102+
batchLogger.error( "Error reading the GT parent directory. Stopping."
103+
+ "\n" + e.getMessage() );
104+
e.printStackTrace();
105+
throw new RuntimeException( e );
106+
}
107+
}
71108

109+
batchLogger.log( "Exporting test results to CTC format.\n" );
72110
final int id = CTCExporter.getAvailableDatasetID( resultsRootPath.toString() );
73111
final String resultsFolder = CTCExporter.getExportTrackingDataPath( resultsRootPath.toString(), id, ExportType.RESULTS, trackmate );
74112
try

0 commit comments

Comments
 (0)