Login  Register

Auto-ROI selection on XY point

Posted by tisalon on May 12, 2018; 8:07pm
URL: http://imagej.273.s1.nabble.com/Auto-ROI-selection-on-XY-point-tp5020658.html

Hi everyone,

I am currently writing a script to measure the fluorescence of moving
objects. For that purpose, I segment images using the WEKA library and then
track the particles with TrackMate. I am aware that I can get the mean and
median fluorescence, but I will need to do some sub-pixel localisation.
Therefore, what I am doing is to extract the XY centres of each track and
now I would like to generate some kind of ROI that cover the whole binary
section. I thought I could make this by calling the magic wand at the point
XY, but seems doWand(imp, x,y,...) does not work. Below the code I am using
for the TrackMate section, which it is indeed a translation to groovy of the
python example from the internet:

//@ ImagePlus imp
//@ File (style = "directory", label = "Output folder") outputFolder
//@ String (label = "Output file name") filename
//@ double (label = "Spot radius", stepSize=0.1) radius
//@ double (label = "Quality threshold") threshold
//@ int (label = "Max frame gap") frameGap
//@ double (label = "Linking max distance") linkingMax
//@ double (label = "Gap-closing max distance") closingMax

import fiji.plugin.trackmate.Model
import fiji.plugin.trackmate.Settings
import fiji.plugin.trackmate.TrackMate

import fiji.plugin.trackmate.detection.LogDetectorFactory

import fiji.plugin.trackmate.tracking.LAPUtils
import fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory

import fiji.plugin.trackmate.action.ExportTracksToXML
import ij.*
import ij.*
import ij.ImagePlus
import ij.WindowManager
import ij.plugin.*


imp = IJ.openImage('http://fiji.sc/samples/FakeTracks.tif')

// Swap Z and T dimensions if T=1
dims = imp.getDimensions() // default order: XYCZT
if (dims[4] == 1) {
        imp.setDimensions( dims[2,4,3] )
}

// Setup settings for TrackMate
settings = new Settings()
settings.setFrom(imp)
settings.dt = 0.05

settings.detectorFactory = new LogDetectorFactory()
settings.detectorSettings = settings.detectorFactory.getDefaultSettings()
println settings.detectorSettings

settings.detectorSettings['RADIUS'] = radius
settings.detectorSettings['THRESHOLD'] = threshold
println settings.detectorSettings

settings.trackerFactory = new SparseLAPTrackerFactory()
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()

settings.trackerSettings['MAX_FRAME_GAP']  = frameGap
settings.trackerSettings['LINKING_MAX_DISTANCE']  = linkingMax
settings.trackerSettings['GAP_CLOSING_MAX_DISTANCE']  = closingMax

// Run TrackMate and store data into Model
model = new Model()
trackmate = new TrackMate(model, settings)

println trackmate.checkInput()
println trackmate.process()
println trackmate.getErrorMessage()

println model.getSpots().getNSpots(true)
println model.getTrackModel().nTracks(true)


for (id in model.getTrackModel().trackIDs( true )) { // loop over tracks
       
        track = model.getTrackModel().trackSpots(1) // get ith-track

        for (spot in track) { // extrack coordinates
        x=spot.getFeature('POSITION_X')
    y=spot.getFeature('POSITION_Y')
    println x
    ij.gui.doWand(imp, x, y, 5.0, "Legacy") // do magic wand on X image
    //IJ.run(imp, "Measure", "") // Measure in original image
       
        }
  }




--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html