Short Description

Batch process on a folder, using a K-Means algorithm for thresholding.

Versions

  • Version 1 • Released on: 2013-08-23 15:02:47
    Download
    Description:

    initial version

    importClass(Packages.icy.file.Saver)
    importClass(Packages.plugins.adufour.thresholder.KMeans)
    importClass(Packages.plugins.adufour.thresholder.Thresholder)
    importClass(Packages.icy.file.Loader)
    importClass(Packages.plugins.tprovoost.scripteditor.uitools.filedialogs.FileDialog)
    importClass(Packages.java.io.File)
    
    sep = File.separator // will be either  or / depending on your OS
    
    // Folder containing the input to batch on
    folderInput = FileDialog.openFolder()
    
    if (folderInput == null)
    	throw "User Cancelled."
    
    // All the files contained inside the inputFolder
    files = folderInput.listFiles()
    
    // folder containing the result
    folderOutput = FileDialog.openFolder()
    
    if (folderOutput == null)
    	throw "User Cancelled."
    
    // fileName (a string) of the output, as a base for the files
    fileName = folderOutput.getPath() + sep
    
    // Loop on every file.
    for (i = 0; i < files.length; i++) {
    	seq = Loader.loadSequence(files[i])
    
    	// computes the kmeans thresholds for automatic thresholding
    	kmeans = KMeans.computeKMeansThresholds(seq, 0, 2, 255)
    
    	// performs the threshold and put the result (a sequence) inside a variable
    	result = Thresholder.threshold(seq, 0, kmeans, false)
    
    	// create a file based on the original sequence name, to which
    	// is added _kmeans. 
    	outputFile = new File(fileName + seq.getName() + "_kmeans.tif")
    
    	// Save the resulting sequence to the file
    	Saver.save(result, outputFile)
    }

Leave a Review