Auto-ROI selection on XY point

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto-ROI selection on XY point

tisalon
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
Reply | Threaded
Open this post in threaded view
|

Re: Auto-ROI selection on XY point

Jan Eglinger
Dear Santiago,

the doWand() method is a *static* method of the ij.IJ utility class [1].
The following call should work:

     IJ.doWand(imp, x, y, 5.0, "Legacy")


A few other comments:

- For questions like this, I warmly recommend using the ImageJ forum
[2], as it permits to use code formatting and syntax highlighting.


 > //@ ImagePlus imp

- When converting from Python to Groovy, there's no need to convert the
comment syntax for script parameters. The new hash-at (#@) syntax [3] is
*language-agnostic* and therefore works in both Python and Groovy.


Cheers
Jan

[1]: http://javadoc.scijava.org/ImageJ1/ij/IJ.html
[2]: http://forum.imagej.net/
[3]: https://imagej.net/Script_Parameters



On 12.05.2018 22:07, tisalon wrote:

> 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
>

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