Skip to content, Skip to search


Jython Scripting

1,227 bytes added, 07:19, 18 October 2011
Create a virtual stack from the TIF files present in a folder and its subfolders, recursively
ImagePlus("Stack from subdirectories", vs).show()
=== Open the slices of a very large multi-image stack file one by one, and save each as a new image file ===
<source lang="python">
# 2011-10-18 Albert Cardona for Nuno da Costa
# Choose a multi-slice image stack file in a virtual way
# and save each slice as an individual image file
# in a user-chosen directory.
import os
from loci.plugins.util import BFVirtualStack
from loci.formats import ChannelSeparator
def run():
# Choose a file to open
od = OpenDialog("Choose multi-image file", None)
srcDir = od.getDirectory()
if srcDir is None:
# User canceled the dialog
path = os.path.join(srcDir, od.getFileName())
# Choose a directory to store each slice as a file
targetDir = DirectoryChooser("Choose target directory").getDirectory()
if targetDir is None:
# User canceled the dialog
# Ready:
cs = ChannelSeparator()
bf = BFVirtualStack(path, cs, False, False, False)
for sliceIndex in xrange(1, bf.getSize() +1):
print "Processing slice", sliceIndex
ip = bf.getProcessor(sliceIndex)
sliceFileName = os.path.join(targetDir, str(sliceIndex) + ".tif")
FileSaver(ImagePlus(str(sliceIndex), ip)).saveAsTiff(sliceFileName)
Emailconfirmed, uploaders