Skip to content

Instantly share code, notes, and snippets.

@hirokai
Created March 15, 2014 23:01
Show Gist options
  • Save hirokai/9575273 to your computer and use it in GitHub Desktop.
Save hirokai/9575273 to your computer and use it in GitHub Desktop.
Batch processing template for Fiji with Jython
# Example of Fiji script for batch processing.
import csv
# Stub
# You can put whatever opearations you want to apply.
def get_radialprofile(imp, cx, cy, r, num_bin)
return None
def process(filename, cx, cy, r, num_bin):
imp = IJ.openImage(filename)
if imp is None:
print "Could not open image from file:", filename
return None
else:
return get_radialprofile(imp, cx, cy, r, num_bin)
# Assume the CSV file has five columns: file path, cx, cy, r, # of bins
infile = 'recipe.csv'
# Open a csv file. csvfile keeps a "file handle".
csvfile = open(infile, 'rb')
# Any error happening inside try block does not stop the execution of script.
try:
# reader is used for reading a csv line by line.
reader = csv.reader(csvfile)
reader.next() # Skip the first row
for row in reader:
if len(row) >= 5:
# '*' operator expands a list to arguments to a function.
profile = process(row[0], *map(int, row[1:5]))
print ",".join(map(str, profile))
# finally block is executed in the end no matter if an error occurs or not.
finally:
csvfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment