Scripting: How to turn SpotDetector output in a list of ROIs?

44 views
Skip to first unread message

Jean-Yves Tinevez

unread,
Feb 8, 2018, 10:20:00 AM2/8/18
to Icy imaging
Hi all,

I am using the Spot Detector in a Python script. 

Everything works fine, and I would like to add the results to the source Sequence, as ROIs (so that they can be saved in the Icy XML file). 

Is there a method that does automagically that? I could iterate through the list of detections and make a ROI for each, but I was wondering if you did not write something that does it at once already.



Fabrice de Chaumont

unread,
Feb 8, 2018, 11:50:35 AM2/8/18
to Icy imaging
Hi !

If you can access the detection already (or the detectionResult ) you can process it with a detection to ROI (static) call:

ArrayList<ROI> roiList = DetectionToROI.convertDetectionToROI( detectionResult );

:)

code here:

package plugins.fab.spotDetector.detector;

import icy.roi.BooleanMask2D;
import icy.roi.ROI;
import icy.type.point.Point5D;

import java.util.ArrayList;

import plugins.fab.spotDetector.DetectionSpot;
import plugins.fab.spotDetector.Point3D;
import plugins.kernel.roi.roi2d.ROI2DArea;
import plugins.kernel.roi.roi3d.ROI3DArea;

public class DetectionToROI {

    public static ArrayList<ROI> convertDetectionToROI(ArrayList<DetectionSpot> detectionList )
    {
        ArrayList<ROI> roiList = new ArrayList<ROI>();
       
        for ( DetectionSpot spot : detectionList )
        {
            ROI roi = null;
            ROI3DArea roi3D = new ROI3DArea();
           
            if ( spot.points.size() == 0 ) continue;
           
            roi3D.beginUpdate();
            try
            {
                for ( Point3D p : spot.points )
                {

                    roi3D.addPoint( (int)p.x , (int)p.y, (int)p.z );
                }
            }finally{
                roi3D.endUpdate();
            }
           
            if ( roi3D.getSizeZ() == 1 ) // check if the sizeZ is 1 and convert to ROI2D
            {
                int z = (int)roi3D.getPosition().getZ();
                BooleanMask2D mask = roi3D.getBooleanMask2D(z, true );               
                ROI2DArea roi2D = new ROI2DArea( mask );
                roi2D.setZ( roi3D.getPosition().z );               
                roi = roi2D;
            }else
            {
                roi = roi3D;
            }
           
            roiList.add( roi );
            // set t for ROI.
            roi.setPosition5D( new Point5D.Double( 
                    roi.getPosition5D().getX(),
                    roi.getPosition5D().getY(),
                    roi.getPosition5D().getZ(),
                    spot.getT(),
                    roi.getPosition5D().getC() ) );
            roi.setName("spot #"+detectionList.indexOf( spot ));
        }       
       
        return roiList;

Jean-Yves Tinevez

unread,
Feb 8, 2018, 11:58:39 AM2/8/18
to Icy imaging


On Thursday, February 8, 2018 at 5:50:35 PM UTC+1, Fabrice de Chaumont wrote:
Hi !

If you can access the detection already (or the detectionResult ) you can process it with a detection to ROI (static) call:

ArrayList<ROI> roiList = DetectionToROI.convertDetectionToROI( detectionResult );


Perfect! This is exactly what I was looking for. Thanks!
 
Reply all
Reply to author
Forward
0 new messages