annotate imagej_basic_ashlar.py @ 0:fd8dfd64f25e draft

"planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
author perssond
date Fri, 12 Mar 2021 00:13:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
1 # @File(label="Select a slide to process") filename
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
2 # @File(label="Select the output location", style="directory") output_dir
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
3 # @String(label="Experiment name (base name for output files)") experiment_name
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
4 # @Float(label="Flat field smoothing parameter (0 for automatic)", value=0.1) lambda_flat
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
5 # @Float(label="Dark field smoothing parameter (0 for automatic)", value=0.01) lambda_dark
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
6
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
7 # Takes a slide (or other multi-series BioFormats-compatible file set) and
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
8 # generates flat- and dark-field correction profile images with BaSiC. The
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
9 # output format is two multi-series TIFF files (one for flat and one for dark)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
10 # which is the input format used by Ashlar.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
11
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
12 # Invocation for running from the commandline:
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
13 #
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
14 # ImageJ --ij2 --headless --run imagej_basic_ashlar.py "filename='input.ext',output_dir='output',experiment_name='my_experiment'"
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
15
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
16 import sys
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
17 from ij import IJ, WindowManager, Prefs
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
18 from ij.macro import Interpreter
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
19 from loci.plugins import BF
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
20 from loci.plugins.in import ImporterOptions
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
21 from loci.formats import ImageReader
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
22 from loci.formats.in import DynamicMetadataOptions
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
23 import BaSiC_ as Basic
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
24
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
25 import pdb
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
26
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
27
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
28 def main():
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
29
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
30 Interpreter.batchMode = True
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
31
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
32 if (lambda_flat == 0) ^ (lambda_dark == 0):
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
33 print ("ERROR: Both of lambda_flat and lambda_dark must be zero,"
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
34 " or both non-zero.")
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
35 return
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
36 lambda_estimate = "Automatic" if lambda_flat == 0 else "Manual"
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
37
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
38 print "Loading images..."
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
39
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
40 # For multi-scene .CZI files, we need raw tiles instead of the
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
41 # auto-stitched mosaic and we don't want labels or overview images. This
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
42 # only affects BF.openImagePlus, not direct use of the BioFormats reader
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
43 # classes which we also do (see below)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
44 Prefs.set("bioformats.zeissczi.allow.autostitch", "false")
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
45 Prefs.set("bioformats.zeissczi.include.attachments", "false")
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
46
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
47 # Use BioFormats reader directly to determine dataset dimensions without
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
48 # reading every single image. The series count (num_images) is the one value
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
49 # we can't easily get any other way, but we might as well grab the others
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
50 # while we have the reader available.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
51 dyn_options = DynamicMetadataOptions()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
52 # Directly calling a BioFormats reader will not use the IJ Prefs settings
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
53 # so we need to pass these options explicitly.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
54 dyn_options.setBoolean("zeissczi.autostitch", False)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
55 dyn_options.setBoolean("zeissczi.attachments", False)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
56 bfreader = ImageReader()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
57 bfreader.setMetadataOptions(dyn_options)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
58 bfreader.id = str(filename)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
59 num_images = bfreader.seriesCount
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
60 num_channels = bfreader.sizeC
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
61 width = bfreader.sizeX
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
62 height = bfreader.sizeY
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
63 bfreader.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
64
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
65 # The internal initialization of the BaSiC code fails when we invoke it via
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
66 # scripting, unless we explicitly set a the private 'noOfSlices' field.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
67 # Since it's private, we need to use Java reflection to access it.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
68 Basic_noOfSlices = Basic.getDeclaredField('noOfSlices')
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
69 Basic_noOfSlices.setAccessible(True)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
70 basic = Basic()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
71 Basic_noOfSlices.setInt(basic, num_images)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
72
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
73 # Pre-allocate the output profile images, since we have all the dimensions.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
74 ff_image = IJ.createImage("Flat-field", width, height, num_channels, 32);
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
75 df_image = IJ.createImage("Dark-field", width, height, num_channels, 32);
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
76
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
77 print("\n\n")
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
78
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
79 # BaSiC works on one channel at a time, so we only read the images from one
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
80 # channel at a time to limit memory usage.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
81 for channel in range(num_channels):
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
82 print "Processing channel %d/%d..." % (channel + 1, num_channels)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
83 print "==========================="
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
84
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
85 options = ImporterOptions()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
86 options.id = str(filename)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
87 options.setOpenAllSeries(True)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
88 # concatenate=True gives us a single stack rather than a list of
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
89 # separate images.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
90 options.setConcatenate(True)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
91 # Limit the reader to the channel we're currently working on. This loop
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
92 # is mainly why we need to know num_images before opening anything.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
93 for i in range(num_images):
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
94 options.setCBegin(i, channel)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
95 options.setCEnd(i, channel)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
96 # openImagePlus returns a list of images, but we expect just one (a
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
97 # stack).
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
98 input_image = BF.openImagePlus(options)[0]
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
99
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
100 # BaSiC seems to require the input image is actually the ImageJ
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
101 # "current" image, otherwise it prints an error and aborts.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
102 WindowManager.setTempCurrentImage(input_image)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
103 basic.exec(
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
104 input_image, None, None,
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
105 "Estimate shading profiles", "Estimate both flat-field and dark-field",
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
106 lambda_estimate, lambda_flat, lambda_dark,
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
107 "Ignore", "Compute shading only"
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
108 )
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
109 input_image.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
110
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
111 # Copy the pixels from the BaSiC-generated profile images to the
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
112 # corresponding channel of our output images.
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
113 ff_channel = WindowManager.getImage("Flat-field:%s" % input_image.title)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
114 ff_image.slice = channel + 1
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
115 ff_image.getProcessor().insert(ff_channel.getProcessor(), 0, 0)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
116 ff_channel.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
117 df_channel = WindowManager.getImage("Dark-field:%s" % input_image.title)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
118 df_image.slice = channel + 1
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
119 df_image.getProcessor().insert(df_channel.getProcessor(), 0, 0)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
120 df_channel.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
121
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
122 print("\n\n")
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
123
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
124 template = '%s/%s-%%s.tif' % (output_dir, experiment_name)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
125 ff_filename = template % 'ffp'
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
126 IJ.saveAsTiff(ff_image, ff_filename)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
127 ff_image.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
128 df_filename = template % 'dfp'
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
129 IJ.saveAsTiff(df_image, df_filename)
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
130 df_image.close()
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
131
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
132 print "Done!"
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
133
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
134
fd8dfd64f25e "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit a8d2367c8c66eecfc2586a593acc8547a7f8611c-dirty"
perssond
parents:
diff changeset
135 main()