Skip to content

Instantly share code, notes, and snippets.

@Yu-AnChen
Last active October 2, 2018 20:28
Show Gist options
  • Save Yu-AnChen/8c87db00fd012d3fb9322d3c57b2cdf6 to your computer and use it in GitHub Desktop.
Save Yu-AnChen/8c87db00fd012d3fb9322d3c57b2cdf6 to your computer and use it in GitHub Desktop.
# @File(label="Select a slide to process") filename
# @File(label="Select the output location", style="directory") output_dir
# @String(label="Experiment name (base name for output files)") experiment_name
# @Integer(label="Rows", value=10) rows
# @Integer(label="Columns", value=10) cols
# Takes a slide (or other multi-series BioFormats-compatible file set) and
# generates flat- and dark-field correction profile images with BaSiC. The
# output format is two multi-series TIFF files (one for flat and one for dark)
# which is the input format used by Ashlar.
# Invocation for running from the commandline:
#
# /Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run
# imagej_mosaic_ashlar.py "filename='input.ext',output_dir='output',
# experiment_name='my_experiment',rows='10',cols='10'"
import sys
from ij import IJ, WindowManager
import ij.plugin.MontageMaker as MM
import ij.process.StackProcessor as StackProc
from ij.macro import Interpreter
from loci.plugins import BF
from loci.plugins.in import ImporterOptions
def main():
Interpreter.batchMode = True
print "Loading images..."
options = ImporterOptions()
options.setId(str(filename))
options.setOpenAllSeries(True)
options.setConcatenate(True)
options.setSplitChannels(True)
imps = BF.openImagePlus(options)
num_channels = len(imps)
w = imps[0].getWidth()
h = imps[0].getHeight()
for channel, imp in enumerate(imps):
title = imp.getTitle()
print "Processing:", title
x, y, c, z, t = imp.getDimensions()
assert z == 1 and c == 1
imp.setDimensions(1, t, 1)
# Generate thumbnail for cycle_offset measurement
mosaic_channel = 0
if channel == mosaic_channel:
StackProc(imp.getStack()).flipVertical()
mosaic = MM().makeMontage2(
imp, cols, rows, 0.1, 1, t, 1, 0, False
)
mosaic.getProcessor().flipVertical()
mosaic_filename = '%s/%s-mosaic_c%s.tif' % (output_dir, experiment_name, mosaic_channel)
IJ.saveAsTiff(mosaic, mosaic_filename)
imp.close()
print "Done!"
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment