comparison imagej2_crop_jython_script.py @ 3:d426c25946d4 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit 8f49f3c66b5a1de99ec15e65c2519a56792f1d56
author imgteam
date Wed, 25 Sep 2024 16:11:17 +0000
parents
children
comparison
equal deleted inserted replaced
2:d7fbe9662213 3:d426c25946d4
1 import sys
2
3 from ij import IJ
4 from ij.plugin import Duplicator
5
6 # Fiji Jython interpreter implements Python 2.5 which does not
7 # provide support for argparse.
8 input_file = sys.argv[-13]
9 xleft = int(sys.argv[-12])
10 width = int(sys.argv[-11])
11 ytop = int(sys.argv[-10])
12 height = int(sys.argv[-9])
13 first_channel = int(sys.argv[-8])
14 last_channel = int(sys.argv[-7])
15 first_slice = int(sys.argv[-6])
16 last_slice = int(sys.argv[-5])
17 first_frame = int(sys.argv[-4])
18 last_frame = int(sys.argv[-3])
19 output_filename = sys.argv[-2]
20 output_datatype = sys.argv[-1]
21
22 # Open the input image file.
23 input_image_plus = IJ.openImage(input_file)
24
25 # Get image dimensions (width, height, nChannels, nSlices, nFrames)
26 image_dims = input_image_plus.getDimensions()
27
28 # Create a copy of the image.
29 input_image_plus_copy = input_image_plus.duplicate()
30
31 # Determine if crop in XY is needed:
32 if xleft != 0 or width != 0 or ytop != 0 or height != 0:
33 # Need to define a ROI
34 if width == 0:
35 width = image_dims[0] - xleft
36 if height == 0:
37 height = image_dims[1] - ytop
38 input_image_plus_copy.setRoi(xleft, ytop, width, height)
39
40 # Replace 0's with default:
41 if last_channel == 0:
42 last_channel = image_dims[2]
43 if last_slice == 0:
44 last_slice = image_dims[3]
45 if last_frame == 0:
46 last_frame = image_dims[4]
47 print("Original dimensions:")
48 print(image_dims)
49 # This will also crop in XY is a ROI has been set
50 input_image_plus_copy = Duplicator().run(input_image_plus_copy, first_channel, last_channel, first_slice, last_slice, first_frame, last_frame)
51 print("Final dimensions:")
52 print(input_image_plus_copy.getDimensions())
53
54 # Save the ImagePlus object as a new image.
55 IJ.saveAs(input_image_plus_copy, output_datatype, output_filename)