Skip to content

Commit

Permalink
fix: remove filter track list
Browse files Browse the repository at this point in the history
  • Loading branch information
Georges El Haddad committed Apr 8, 2020
1 parent 3b5f1db commit a3de11f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 32 deletions.
78 changes: 47 additions & 31 deletions src/spotmetrics/analyzer/AnalysisEngine.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package spotmetrics.analyzer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import fiji.plugin.trackmate.Logger;
import fiji.plugin.trackmate.Model;
import fiji.plugin.trackmate.Settings;
Expand Down Expand Up @@ -177,6 +175,7 @@ public final Map<String, MyTrack> trackSpots() {
calibrateImageDimensions();

parentFrame.updateProgressBar("Setting up TrackMate ...");
IJ.log("Setting up TrackMate ...");

Model model = new Model();
model.setLogger(Logger.IJ_LOGGER);
Expand Down Expand Up @@ -209,13 +208,17 @@ public final Map<String, MyTrack> trackSpots() {
if (ok) {
boolean success = false;
parentFrame.updateProgressBar("Detecting spots ...");
IJ.log("Detecting spots ...");

success = trackMate.execDetection();
if (!success) {
IJ.error("TrackMate Error - Detection", trackMate.getErrorMessage());
}

if (success) {
parentFrame.updateProgressBar("Initial spot filtering ...");
IJ.log("Initial spot filtering ...");

success = trackMate.execInitialSpotFiltering();
if (!success) {
IJ.error("TrackMate Error - Initial Filtering", trackMate.getErrorMessage());
Expand All @@ -224,6 +227,8 @@ public final Map<String, MyTrack> trackSpots() {

if (success) {
parentFrame.updateProgressBar("Spot filtering ...");
IJ.log("Spot filtering ...");

success = trackMate.execSpotFiltering(false);
if (!success) {
IJ.error("TrackMate Error - Spot Filtering", trackMate.getErrorMessage());
Expand All @@ -232,6 +237,8 @@ public final Map<String, MyTrack> trackSpots() {

if (success) {
parentFrame.updateProgressBar("Tracking spots ...");
IJ.log("Tracking spots ...");

success = trackMate.execTracking();
if (!success) {
IJ.error("TrackMate Error - Tracking", trackMate.getErrorMessage());
Expand All @@ -240,6 +247,8 @@ public final Map<String, MyTrack> trackSpots() {

if (success) {
parentFrame.updateProgressBar("Track filtering ...");
IJ.log("Track filtering ...");

success = trackMate.execTrackFiltering(false);
if (!success) {
IJ.error("TrackMate Error - Track Filtering", trackMate.getErrorMessage());
Expand All @@ -252,6 +261,7 @@ public final Map<String, MyTrack> trackSpots() {

for (Integer trackId : trackIds) {
Set<Spot> spots = trackModel.trackSpots(trackId);
// IJ.log("Running through Track ID "+trackId+" ...");

MyTrack tr = new MyTrack();
tr.setLabel("Track_" + String.format("%04d", trackId));
Expand Down Expand Up @@ -283,9 +293,13 @@ public final Map<String, MyTrack> trackSpots() {
else {
IJ.error("TrackMate Error - Settings", trackMate.getErrorMessage());
}

parentFrame.updateProgressBar("Syncing tracks to video range ...");
filterTrackList(tracksMap, model);

// parentFrame.updateProgressBar("Syncing tracks to video range ...");
// IJ.log("Syncing tracks to video range ...");
//
// IJ.log("Before Filter: tracksMap.size() == "+tracksMap.size());
// filterTrackList(tracksMap, model);
// IJ.log("After Filter: tracksMap.size() == "+tracksMap.size());

model = null;
settings = null;
Expand All @@ -294,31 +308,33 @@ public final Map<String, MyTrack> trackSpots() {
return tracksMap;
}

private final void filterTrackList(Map<String, MyTrack> tracksMap, Model model) {
//Only keep the tracks who have spots between startFrame and endFrame
//Remove all tracks that don't match
//Remove all spots below and above the range

parentFrame.updateProgressBar("Synchronizng tracks to video range ... ");

List<String> deleteTrackIDs = new ArrayList<String>();

Iterator<MyTrack> iter = tracksMap.values().iterator();
while (iter.hasNext()) {
MyTrack track = iter.next();

if (track.getTrackDuration() != imagePlus.getStackSize()) {
deleteTrackIDs.add(track.getLabel());
}
}

for (String trackID : deleteTrackIDs) {
tracksMap.remove(trackID);
}

deleteTrackIDs.clear();
deleteTrackIDs = null;
}
// private final void filterTrackList(Map<String, MyTrack> tracksMap, Model model) {
// //Only keep the tracks who have spots between startFrame and endFrame
// //Remove all tracks that don't match
// //Remove all spots below and above the range
//
// parentFrame.updateProgressBar("Synchronizng tracks to video range ... ");
//
// List<String> deleteTrackIDs = new ArrayList<String>();
//
// Iterator<MyTrack> iter = tracksMap.values().iterator();
// while (iter.hasNext()) {
// MyTrack track = iter.next();
//
// IJ.log("Track Duration = "+track.getTrackDuration()+" != stackSize = "+imagePlus.getStackSize());
// if (track.getTrackDuration() != imagePlus.getStackSize()) {
// deleteTrackIDs.add(track.getLabel());
// IJ.log("Delete track: "+track.getLabel());
// }
// }
//
// for (String trackID : deleteTrackIDs) {
// tracksMap.remove(trackID);
// }
//
// deleteTrackIDs.clear();
// deleteTrackIDs = null;
// }

public final void cropVideo() {
if(imagePlus != null) {
Expand Down
7 changes: 6 additions & 1 deletion src/spotmetrics/ui/SpotMetricsFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.UIManager;

import ij.IJ;
import ij.ImagePlus;
import spotmetrics.SpotMetrics;
import spotmetrics.analyzer.AnalysisEngine;
Expand Down Expand Up @@ -338,8 +340,11 @@ public void run() {
engine.processVideo();
engine.setTrackingOptions(trackOptions);
Map<String, MyTrack> tracksMap = engine.trackSpots();


// IJ.log("Is tracksMap null? "+(tracksMap == null));

if (tracksMap != null) {
IJ.log("tracksMap size = "+tracksMap.size());
spotsPanel.clearSpotTreeSelection();
spotsPanel.setSpotTracks(tracksMap, analysisPanel.getXoffset(), analysisPanel.getYoffset(), analysisPanel.getWoffset(), analysisPanel.getHoffset(), true);
spotsPanel.setImagePlus(engine.getImagePlus());
Expand Down

0 comments on commit a3de11f

Please sign in to comment.