Script

Detect spot and change parameter along time with batch input and output

Publication ID: ICY-T7C3H2

Short Description

This script is a modification of the script "Detect spot and change parameter along time" but it is using batch inputs and outputs. The user specifies a list of image files to process with the spot detector plugin, the sequences are then automatically loaded, processed, and results are saved locally. The parameter of detection for each frame is varied according to a user-defined formula. As an example, a linear growth formulat is used for the second scale of the transform between two bounds. Required plugins: - Spot Detector - Spot Tracking - Track Manager

Versions

  • Version 1 • Released on: 2013-04-03 00:27:34
    Download
    Description:

    initial version

    importClass(Packages.icy.type.DataType)
    importClass(Packages.java.util.ArrayList)
    importClass(Packages.java.awt.geom.Point2D)
    importClass(Packages.java.io.File)
    importClass(Packages.java.awt.image.BufferedImage)
    
    importClass(Packages.icy.file.Loader)
    importClass(Packages.icy.gui.dialog.MessageDialog)
    importClass(Packages.icy.sequence.Sequence)
    importClass(Packages.icy.file.xls.XlsManager)
    importClass(Packages.icy.file.FileUtil)
    importClass(Packages.icy.file.Saver)
    importClass(Packages.icy.type.DataType)
    importClass(Packages.icy.image.IcyBufferedImage)
    importClass(Packages.icy.gui.viewer.Viewer)
    importClass(Packages.icy.canvas.Canvas2D)
    
    importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)
    
    importClass(Packages.plugins.fab.spotDetector.detector.UDWTWavelet)
    importClass(Packages.plugins.fab.spotDetector.GlobalDetectionToken)
    importClass(Packages.plugins.fab.spotDetector.DetectionSpot)
    
    // let the user select multiple files
    var files = FileDialog.openMulti() 
    if (files == null) throw "User cancelled!"
    // create a detector
    detector = new UDWTWavelet()
    // scale 2 parameter is linearly increasing over time betweeen those bounds
    lowerBoundThreshold2 = 10
    upperBoundThreshold2 = 100
    
    // iterate over the selected image files
    for (j = 0; j < files.length; ++j) {
        var f = files[j]
        // load the sequence
        sequence = Loader.loadSequence(f)
        println("sequence: "+ sequence.getName());
        inputSequenceFile = f
        file = inputSequenceFile.getAbsolutePath();
        file = file.substring( 0 , file.length() - inputSequenceFile.getName().length() );
        // create a folder structure to save results locally
        folder = file;
        dirResult = new File(folder, FileUtil.separator + "saveDetections");  
        // create a XLS file to output results
        XLSFile = new File ( folder + FileUtil.separator + "saveDetections" + FileUtil.separator + inputSequenceFile.getName()+".xls" );		
        if(!dirResult.exists()) dirResult.mkdir();
        xlsManager = new XlsManager( XLSFile );
        row = 0;
        // page that contains the details of the detections
        xlsManager.createNewPage( FileUtil.getFileName( sequence.getName() ) + " detections");			
    	row++;
    	xlsManager.setLabel( 0 , row , "Detection #" );
    	xlsManager.setLabel( 1 , row , "Surface" );
    	xlsManager.setLabel( 2 , row , "x" );
    	xlsManager.setLabel( 3 , row , "y" );
    	xlsManager.setLabel( 4 , row , "z" );
    	xlsManager.setLabel( 5 , row , "t" );
    	xlsManager.setLabel( 6 , row , "min intensity" );
    	xlsManager.setLabel( 7 , row , "max intensity" );
    	xlsManager.setLabel( 8 , row , "average intensity" );
    	row++;
    
    	numDetections = new ArrayList(sequence.getSizeT());
    	scale2Parameters = new ArrayList(sequence.getSizeT());
    	binarySequence = new Sequence();
    	overlayedImage = new Sequence();
    	// iterate over the sequence frames
    	for ( frameNumber = 0 ; frameNumber < sequence.getSizeT() ; frameNumber++ ){
    		// This varies the threshold along time. In this example, at each frame the detector will become more and more sensitive
    		parameterForScale2 = lowerBoundThreshold2 + (upperBoundThreshold2 - lowerBoundThreshold2)*(frameNumber)/(sequence.getSizeT() - 1)
    		scaleParameters = [0, parameterForScale2] 
    		scale2Parameters.add(parameterForScale2);
    
    		// create a temp sequence to perform the detection on it.
    		image = sequence.getImage( frameNumber , 0 ) // get image at t and z=0	
    		println("Time t = " + frameNumber );
    		println("Scale 2 parameter = " + parameterForScale2 );
    
    		tmpSequence = new Sequence();
    		tmpSequence.addImage( 0 , image );	
    		detector.detect(tmpSequence, false, false, scaleParameters)	
    		detectionResult = detector.getDetectionResult();
    		detectionSize = detectionResult.size();
    		numDetections.add(detectionSize);
    
    		// save results in the XLS file
    		detectionNumber = 0;
    		for (i = 0; i < detectionSize; i++)
    		{
    			detectionSpot = detectionResult.get(i) // get the spot
    			xlsManager.setNumber( 0 , row , detectionNumber );
    			xlsManager.setNumber( 1 , row , detectionSpot.points.size() );
    			xlsManager.setNumber( 2 , row , detectionSpot.getMassCenter().x );
    			xlsManager.setNumber( 3 , row , detectionSpot.getMassCenter().y );
    			xlsManager.setNumber( 4 , row , detectionSpot.getMassCenter().z );
    			xlsManager.setNumber( 5 , row , frameNumber );
    			xlsManager.setNumber( 6 , row , detectionSpot.minIntensity );
    			xlsManager.setNumber( 7 , row , detectionSpot.maxIntensity );
    			xlsManager.setNumber( 8 , row , detectionSpot.meanIntensity );
    			row++;
    			detectionNumber++;
    		}
    		// get the number of detection
    		println("Number of detection : " + detectionSize);
    		
    		// create a binary mask for detections
    		binaryImage = new IcyBufferedImage(tmpSequence.getSizeX(), tmpSequence.getSizeY(), 1, DataType.BYTE);
    		binaryData = binaryImage.getDataXYAsByte(0);
    		for (i = 0; i < detectionSize; i++) { // cycle over all the detections.
            		spot = detectionResult.get(i) // get the spot
     			for (k = 0; k < spot.points.size(); k++)
     			{
     				point = spot.points.get(k);
     				binaryData[point.x + point.y*tmpSequence.getSizeX()] = 127;
     			}
    		}
    		binarySequence.addImage(frameNumber, binaryImage);
    	}
    	// summarize detection results in a separate page of the XLS file
    	xlsManager.createNewPage( "Summary" );			
    	row = 0;
    	xlsManager.setLabel( 0 , row , "Time" );	
    	xlsManager.setLabel( 1 , row , "Number of detections" );
    	xlsManager.setLabel( 2 , row , "Scale 2 parameter" );	
    	row++;
    	for ( frameNumber = 0 ; frameNumber < sequence.getSizeT() ; frameNumber++ ){
    		xlsManager.setNumber( 0 , row , frameNumber);
    		xlsManager.setNumber( 1 , row , numDetections.get(frameNumber));
    		xlsManager.setNumber( 2 , row , scale2Parameters.get(frameNumber));
    		row++;
    	}
    	// save the XLS file
    	xlsManager.SaveAndClose();
    	// save the binary sequence of images
    	binaryFile = new File(folder + FileUtil.separator + "saveDetections" + FileUtil.separator + inputSequenceFile.getName()+"_binary"+".tif" );
    	Saver.save(binarySequence, binaryFile, false)
    }
    

Leave a Review