annotate imagej_basic_ashlar_filepattern.py @ 0:cad3339b566b draft default tip

"planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
author perssond
date Tue, 08 Dec 2020 20:57:09 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
1 # @String(label="Enter a filename pattern describing the TIFFs to process") pattern
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
2 # @File(label="Select the output location", style="directory") output_dir
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
3 # @String(label="Experiment name (base name for output files)") experiment_name
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
4 # @Float(label="Flat field smoothing parameter (0 for automatic)", value=0.1) lambda_flat
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
5 # @Float(label="Dark field smoothing parameter (0 for automatic)", value=0.01) lambda_dark
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
6
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
7 import sys
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
8 import os
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
9 import re
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
10 import collections
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
11 from ij import IJ, WindowManager, ImagePlus, ImageStack
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
12 from ij.io import Opener
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
13 from ij.macro import Interpreter
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
14 import BaSiC_ as Basic
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
15
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
16
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
17 def enumerate_filenames(pattern):
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
18 """Return filenames matching pattern (a str.format pattern containing
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
19 {channel} and {tile} placeholders).
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
20
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
21 Returns a list of lists, where the top level is indexed by channel number
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
22 and the bottom level is sorted filenames for that channel.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
23
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
24 """
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
25 (base, pattern) = os.path.split(pattern)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
26 regex = re.sub(r'{([^:}]+)(?:[^}]*)}', r'(?P<\1>.*?)',
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
27 pattern.replace('.', '\.'))
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
28 tiles = set()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
29 channels = set()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
30 num_images = 0
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
31 # Dict[channel: int, List[filename: str]]
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
32 filenames = collections.defaultdict(list)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
33 for f in os.listdir(base):
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
34 match = re.match(regex, f)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
35 if match:
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
36 gd = match.groupdict()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
37 tile = int(gd['tile'])
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
38 channel = int(gd['channel'])
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
39 tiles.add(tile)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
40 channels.add(channel)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
41 filenames[channel].append(os.path.join(base, f))
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
42 num_images += 1
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
43 if len(tiles) * len(channels) != num_images:
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
44 raise Exception("Missing some image files")
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
45 filenames = [
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
46 sorted(filenames[channel])
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
47 for channel in sorted(filenames.keys())
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
48 ]
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
49 return filenames
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
50
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
51
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
52 def main():
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
53
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
54 Interpreter.batchMode = True
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
55
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
56 if (lambda_flat == 0) ^ (lambda_dark == 0):
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
57 print ("ERROR: Both of lambda_flat and lambda_dark must be zero,"
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
58 " or both non-zero.")
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
59 return
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
60 lambda_estimate = "Automatic" if lambda_flat == 0 else "Manual"
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
61
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
62 #import pdb; pdb.set_trace()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
63 print "Loading images..."
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
64 filenames = enumerate_filenames(pattern)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
65 num_channels = len(filenames)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
66 num_images = len(filenames[0])
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
67 image = Opener().openImage(filenames[0][0])
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
68 width = image.width
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
69 height = image.height
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
70 image.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
71
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
72 # The internal initialization of the BaSiC code fails when we invoke it via
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
73 # scripting, unless we explicitly set a the private 'noOfSlices' field.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
74 # Since it's private, we need to use Java reflection to access it.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
75 Basic_noOfSlices = Basic.getDeclaredField('noOfSlices')
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
76 Basic_noOfSlices.setAccessible(True)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
77 basic = Basic()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
78 Basic_noOfSlices.setInt(basic, num_images)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
79
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
80 # Pre-allocate the output profile images, since we have all the dimensions.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
81 ff_image = IJ.createImage("Flat-field", width, height, num_channels, 32);
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
82 df_image = IJ.createImage("Dark-field", width, height, num_channels, 32);
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
83
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
84 print("\n\n")
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
85
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
86 # BaSiC works on one channel at a time, so we only read the images from one
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
87 # channel at a time to limit memory usage.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
88 for channel in range(num_channels):
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
89 print "Processing channel %d/%d..." % (channel + 1, num_channels)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
90 print "==========================="
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
91
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
92 stack = ImageStack(width, height, num_images)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
93 opener = Opener()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
94 for i, filename in enumerate(filenames[channel]):
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
95 print "Loading image %d/%d" % (i + 1, num_images)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
96 image = opener.openImage(filename)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
97 stack.setProcessor(image.getProcessor(), i + 1)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
98 input_image = ImagePlus("input", stack)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
99
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
100 # BaSiC seems to require the input image is actually the ImageJ
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
101 # "current" image, otherwise it prints an error and aborts.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
102 WindowManager.setTempCurrentImage(input_image)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
103 basic.exec(
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
104 input_image, None, None,
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
105 "Estimate shading profiles", "Estimate both flat-field and dark-field",
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
106 lambda_estimate, lambda_flat, lambda_dark,
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
107 "Ignore", "Compute shading only"
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
108 )
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
109 input_image.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
110
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
111 # Copy the pixels from the BaSiC-generated profile images to the
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
112 # corresponding channel of our output images.
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
113 ff_channel = WindowManager.getImage("Flat-field:%s" % input_image.title)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
114 ff_image.slice = channel + 1
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
115 ff_image.getProcessor().insert(ff_channel.getProcessor(), 0, 0)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
116 ff_channel.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
117 df_channel = WindowManager.getImage("Dark-field:%s" % input_image.title)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
118 df_image.slice = channel + 1
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
119 df_image.getProcessor().insert(df_channel.getProcessor(), 0, 0)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
120 df_channel.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
121
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
122 print("\n\n")
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
123
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
124 template = '%s/%s-%%s.tif' % (output_dir, experiment_name)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
125 ff_filename = template % 'ffp'
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
126 IJ.saveAsTiff(ff_image, ff_filename)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
127 ff_image.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
128 df_filename = template % 'dfp'
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
129 IJ.saveAsTiff(df_image, df_filename)
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
130 df_image.close()
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
131
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
132 print "Done!"
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
133
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
134
cad3339b566b "planemo upload for repository https://github.com/ohsu-comp-bio/basic-illumination commit d06e0682d1847fae0d5a464d7aa9e47e40d31fe7-dirty"
perssond
parents:
diff changeset
135 main()