TrackMate Auto Spot Filters

Hi everyone!

I am scripting TrackMate in a Python file. I want to use a quality spot filter on my data that is set based on the ‘Auto’ filter level that is an option presented in the TrackMate GUI. Following the example from Setting TrackFilter values dynamically , where a similar thing was accomplished for track filters, I have tried initially running a stunted version of TrackMate to obtain the quality values, then feed it back into a full run of TrackMate later to set the spot filter dynamically. This is what I’ve come up with:

model = Model()
settings = Settings()
trackmate = TrackMate(model, settings)

spotFeatureValues = model.getFeatureModel().getSpotFeatureValues()
featureValues = spotFeatureValues.get('QUALITY')
optimalMeanIntensity = fiji.plugin.trackmate.util.TMUtils.otsuThreshold(featureValues)

However, it returns the error:

'fiji.plugin.trackmate.FeatureModel' object has no attribute 'getSpotFeatureValues'

I have found the attribute ‘getSpotFeatures’ to work, however it just appears to be a list of names of the different features. I got the initial idea to use ‘getSpotFeatureValues’ from on the TrackMate repository, however I have not seen it documented on any other page.

I was wondering if anyone had any idea what the appropriate attribute is to use in order to obtain the quality values of my spots. Any help would be appreciated!

Hi @vanessa.king

The quality is just a regular Spot feature. In the case of spots, they are stored directly in the spot objects. So to get the Quality of a spot, you just call

double q = spot.getFeature( 'QUALITY');

Hi @tinevez,

Sorry for digging back this old post but I have a similar question and thought it would be smarter than multiplying topics…

I have a function where I’m using TrackMate to find the peaks in 3D objects to count number of objects. This is the function:

def count_cellDetection3D(implus, rad, thresh, subpix, med):
    """Function to detect the cells in 3D using TrackMate

        implus {imagePlus} -- ImagePlus of the image to use for detection
        rad    {int}       -- Radius of the cell to detect, half the diameter
        thresh {int}       -- Intensity threshold for the detection
        subpix {bool}      -- Option for subpixel detection
        med {bool}         -- Option for median filter before detection

        cellCount {int} -- Number of cells found
    dim = implus.getDimensions()
    cal = implus.getCalibration()

    implus2 = implus.duplicate()

    # Set the parameters for LogDetector
    img           = ImageJFunctions.wrap(implus2)
    interval      = img
    # cal           = implus.getCalibration()
    # calibration = [round(cal.pixelWidth,3), round(cal.pixelHeight,3), round(cal.pixelDepth,3)]
    calibration   = [cal.pixelWidth, cal.pixelHeight, cal.pixelDepth]

    radius     = rad  # the radius is half the diameter
    threshold  = thresh
    doSubpixel = subpix
    doMedian   = med

    # print cal.pixelDepth

    # Setup spot detector (see
    # public LogDetector(RandomAccessible<T> img,
    #            Interval interval,
    #            double[] calibration,
    #            double radius,
    #            double threshold,
    #            boolean doSubPixelLocalization,
    #            boolean doMedianFilter)

    detector = LogDetector(img, interval, calibration, radius,
                           threshold, doSubpixel, doMedian)

    # Start processing and display the results
    if detector.process():
        # Get the list of peaks found
        peaks = detector.getResult()
        # print str(len(peaks)), "peaks were found."

        # Add points to ROI manager
        rm = RoiManager.getInstance()
        if not rm:
            rm = RoiManager()

        # Loop through all the peak that were found
        for peak in peaks:
            # Print the current coordinates
            # print peak.getDoublePosition(0), peak.getDoublePosition(1), peak.getDoublePosition(2)
            # Add the current peak to the Roi manager
            roi = PointRoi(peak.getDoublePosition(0) / cal.pixelWidth,
                           peak.getDoublePosition(1) / cal.pixelHeight)
            # print peak.getDoublePosition(2)/cal.pixelDepth
                int(round(peak.getDoublePosition(2) / cal.pixelDepth)) + 1)
        # Show all ROIs on the image
        # rm.runCommand(imp2, "Show All")
        cellCount = rm.getCount()
        # Close the duplicate
        implus2.changes = False
        print "The detector could not process the data."
    return cellCount

As you can see from this code, there’s no Spots but I would still like to use some of the intensity filters that the GUI offers to only find the peak maximas corresponding to my objects. Is there a simple way using this function ?

Thank you very much.

Hello @lguerard

I will tell but only if you make a new post :slight_smile:

1 Like