Short Description

Detection script with post processing: box around mass center of each detection and display a ROI. Computes the sum of pixel.

Versions

  • Version 2 • Released on: 2014-03-05 14:46:37
    Download
    Description:

    My mistake: in the previous version I show 2 way of doing the sum i.e. a+=b and a=a+b... but I was doing both, so the intensity was doubled.

    importClass(Packages.icy.gui.dialog.MessageDialog)
    importClass(Packages.icy.sequence.Sequence)
    importClass(Packages.java.util.ArrayList)
    importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)
    importClass(Packages.icy.roi.ROI2DRectangle)
    importClass(java.awt.geom.Point2D)
    
    // creates a detector
    detector = new UDWTWavelet()
    
    
    // get the current sequence focused by the user
    sequence = getSequence()
    
    
    
    // check if the sequence exists
    if ( sequence == null )
    {
            MessageDialog.showDialog("Please open a sequence first", MessageDialog.INFORMATION_MESSAGE );
            throw "no sequence"; // stops the script and say why
    }
    
    image = sequence.getImage( 0 , 0 ) // get image at t=0 and z=0
    
    // enable scale 2 with a coefficient of 100. (scale 1 is disabled here as the parameter is 0)
    scaleParameters = [0, 100]
    
    // performs the detection
    detector.detect(sequence, false, false, scaleParameters)
    
    detectionResult = detector.getDetectionResult();
    
    // get the number of detection
    detectionSize = detectionResult.size();
    println("Number of detection : " + detectionSize);
    
    // this is the parameters you asked for: considering the center of mass,
    // the algo will look in a box of side boxSize*2+1 where the center of mass is
    // the center of this box
    //
    // for boxSize = 2
    //
    // *****
    // *****
    // **X**
    // *****
    // *****
    //
    // with * : pixel considered for intensity sum
    // X: location of center of mass
    
    boxSize = 2;
    
    sequence.removeAllROI() // remove all existing ROI in sequence
    
    for (i = 0; i < detectionSize; i++) { // cycle over all the detections.
            spot = detectionResult.get(i) // get the spot
            surface = spot.points.size() // retreive the surface of this spot
            //println( "surface:" + surface )
    
            // filter by size
            keepSpot = true // flag to filter spots.
    
            if (surface < 10) keepSpot = false // remove too small spots
            if (surface > 60) keepSpot = false // remove too big spots
    
            if (!keepSpot) continue // if keepSpot if false, stop this loop and continue with next spot
    
            // get mass center.
            massCenter = spot.getMassCenter()
    
            x = massCenter.x;
            y = massCenter.y;
    
            // remove spot if mass center too close from borders
            if (x - boxSize < 0) keepSpot = false;
            if (y - boxSize < 0) keepSpot = false;
            if (x + boxSize > sequence.getWidth()) keepSpot = false;
            if (y + boxSize > sequence.getHeight()) keepSpot = false;
    
            if (!keepSpot) continue
    
            //println("surface:" + surface)
    
            // computes sum of value around the mass center considering the masscenter
            intensitySum = 0
            for (u = x - boxSize; u < x + boxSize+1; u++)
            {
                    for (v = y - boxSize; v < y + boxSize+1; v++) {
    
                            intensitySum = intensitySum + image.getData( u, v, 0 ) // get data of pixel at u,v, channel 0                  
                    }
            }
    
            // display where the detection has been found.
            // create a ROI
    
            roi = new ROI2DRectangle(
                    new Point2D.Double( x-boxSize , y-boxSize ),
                    new Point2D.Double( x+boxSize+1 , y+boxSize+1 ),
                    false ); // false: say to the system that the ROI is not in creation mode.
                    
            sequence.addROI( roi ); // add the ROI to the sequence
    
            println( "intensity sum: " + intensitySum ); // output results
    
    }
    
  • Version 1 • Released on: 2013-03-08 17:13:40
    Download
    Description:

    initial version

    importClass(Packages.icy.gui.dialog.MessageDialog)
    importClass(Packages.icy.sequence.Sequence)
    importClass(Packages.java.util.ArrayList)
    importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)
    importClass(Packages.icy.roi.ROI2DRectangle)
    importClass(java.awt.geom.Point2D)
    
    // creates a detector
    detector = new UDWTWavelet()
    
    
    // get the current sequence focused by the user
    sequence = getSequence()
    
    
    
    // check if the sequence exists
    if ( sequence == null )
    {
            MessageDialog.showDialog("Please open a sequence first", MessageDialog.INFORMATION_MESSAGE );
            throw "no sequence"; // stops the script and say why
    }
    
    image = sequence.getImage( 0 , 0 ) // get image at t=0 and z=0
    
    // enable scale 2 with a coefficient of 100. (scale 1 is disabled here as the parameter is 0)
    scaleParameters = [0, 100]
    
    // performs the detection
    detector.detect(sequence, false, false, scaleParameters)
    
    detectionResult = detector.getDetectionResult();
    
    // get the number of detection
    detectionSize = detectionResult.size();
    println("Number of detection : " + detectionSize);
    
    // this is the parameters you asked for: considering the center of mass,
    // the algo will look in a box of side boxSize*2+1 where the center of mass is
    // the center of this box
    //
    // for boxSize = 2
    //
    // *****
    // *****
    // **X**
    // *****
    // *****
    //
    // with * : pixel considered for intensity sum
    // X: location of center of mass
    
    boxSize = 2;
    
    sequence.removeAllROI() // remove all existing ROI in sequence
    
    for (i = 0; i < detectionSize; i++) { // cycle over all the detections.
            spot = detectionResult.get(i) // get the spot
            surface = spot.points.size() // retreive the surface of this spot
            //println( "surface:" + surface )
    
            // filter by size
            keepSpot = true // flag to filter spots.
    
            if (surface < 10) keepSpot = false // remove too small spots
            if (surface > 60) keepSpot = false // remove too big spots
    
            if (!keepSpot) continue // if keepSpot if false, stop this loop and continue with next spot
    
            // get mass center.
            massCenter = spot.getMassCenter()
    
            x = massCenter.x;
            y = massCenter.y;
    
            // remove spot if mass center too close from borders
            if (x - boxSize < 0) keepSpot = false;
            if (y - boxSize < 0) keepSpot = false;
            if (x + boxSize > sequence.getWidth()) keepSpot = false;
            if (y + boxSize > sequence.getHeight()) keepSpot = false;
    
            if (!keepSpot) continue
    
            //println("surface:" + surface)
    
            // computes sum of value around the mass center considering the masscenter
            intensitySum = 0
            for (u = x - boxSize; u < x + boxSize+1; u++)
            {
                    for (v = y - boxSize; v < y + boxSize+1; v++) {
    
                            intensitySum = intensitySum + image.getData( u, v, 0 ) // get data of pixel at u,v, channel 0
                            // same as
                            intensitySum += image.getData( u, v, 0 ) // get data of pixel at u,v, channel 0
                    }
            }
    
            // display where the detection has been found.
            // create a ROI
    
            roi = new ROI2DRectangle(
                    new Point2D.Double( x-boxSize , y-boxSize ),
                    new Point2D.Double( x+boxSize+1 , y+boxSize+1 ),
                    false ); // false: say to the system that the ROI is not in creation mode.
                    
            sequence.addROI( roi ); // add the ROI to the sequence
    
            println( "intensity sum: " + intensitySum ); // output results
    
    }
    

Leave a Review