Skip to content

Instantly share code, notes, and snippets.

@romainGuiet
Created August 19, 2019 07:51
Show Gist options
  • Save romainGuiet/0dfe09a71a3e08ba5b6b0afa91255ec8 to your computer and use it in GitHub Desktop.
Save romainGuiet/0dfe09a71a3e08ba5b6b0afa91255ec8 to your computer and use it in GitHub Desktop.
import ij.*
import ij.plugin.Duplicator
import ij.io.FileSaver
/**
*
* Here is a groovy script which:
* - Gets information about the current ImagePlus File (via imp.getOriginalFileInfo()),
* - Retrieves its directory
* - Creates an output subfolder
* - Saves an output file
*
* WORKS both with an open image or with the “Batch” command from the script editor !!!
*
*/
#@ImagePlus imp
//imp.show() // optional
// get some info about the image
def info = imp.getOriginalFileInfo()
def dir = info.directory
def fileName = info.fileName
// create an output dire ,and prepare output file path
def output_dir = new File( dir , "output" )
output_dir.mkdirs()
def output_path = new File ( output_dir , "firstSlice_" + fileName )
// Do something, here duplicate first slice
def first_slice = new Duplicator().run(imp, 1, 1, 1, 1, 1, 1);
// save file
def fs = new FileSaver(first_slice)
fs.saveAsTiff(output_path.toString() )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment