Need help or advice ? Come to the Icy club ! - Every Wenesday morning from 9h30 to 12h30 - Francois Jacob Building - Main hall - Pasteur
Register

Detection script using WAT for each ROI

by fab / Fabrice de Chaumont

Performs detection using WAT computation for each ROI independently. Practically, the script saves all the ROIs of a sequence, and then restores each ROI one after the other, and repeat the detection algorithm for each ROI.

version 1 (last version):

download to use and modify in Icy. How do I use scripts ? A Problem ? ask the community.
Changelog for this version: 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)

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

// store the list of ROI

roiList = sequence.getROIs();

try // this keyword is use to prevent problems during exectution of the script. (See finally keyword at the end of the script)
{

	// loop over all the ROIs
	for ( i = 0 ; i < roiList.size() ; i++ )
	{
		currentROI = roiList.get( i );
	
		// remove all ROIs in the sequence, and add the currentROI.
		sequence.removeAllROI();
		sequence.addROI( currentROI );
	
		// perform detection
	
		// creates a detector
		
		detector = new UDWTWavelet()
	
		// 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, // sequence to perform detection
					false, // false: detect bright spot over dark background.
					true,  // true: use WAT computed in the union of ROIs present in sequence.
					scaleParameters)
	
		detectionResult = detector.getDetectionResult();
	
		// the detection is global to the image,
		// so we now need to find the detections within the ROI
		// we store them in filteredDetectionList
	 	
	 	var filteredDetectionList = new Array();
		
		detectionSize = detectionResult.size();
		for ( detectionIndex = 0; detectionIndex < detectionSize; detectionIndex++) { // cycle over all the detections.
	        spot = detectionResult.get( detectionIndex );
	        if ( currentROI.contains( spot.getMassCenter().x , spot.getMassCenter().y , spot.getMassCenter().z , 0 , 0 ) ) // the last 2 zero are for t and channel
			{
				filteredDetectionList.push( spot );
			}
		}
		
		// get the number of detection in ROI.
		detectionSize = filteredDetectionList.length;
		println("ROI Name: " + currentROI.getName() );
		println("Number of detection : " + detectionSize);
		
	}
}
finally 			
{
	// if anything goes wrong while running the part of script in the try section,
	// the execution will jump to this 'finally' statement.
	// And if everything worked fine, this section will be executed anyway to restore the ROIs.	

	// restore all ROIs.
	sequence.removeAllROI();
	for ( i = 0 ; i < roiList.size() ; i++ )
	{
		currentROI = roiList.get( i );
		sequence.addROI( currentROI );
	}	
}

// end of script.

// ( if you need specific output or display please check others scripts available on the website )

This script has no documentation. A Problem ? ask the community.



Icy script publication Id : E7E6L5