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

Batch Auto Threshold

by tprovoost / Thomas Provoost

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

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

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, outputFile)

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

Icy script publication Id : R7X8B4