4141
4242interpolation_mode = 1 # 0: Nearest-neighbor, 1: Bi-linear , 2: Bi-quadratic, 3: Bi-cubic, 4: Bi-quartic, 5: Bi-quintic
4343
44+ IJTimeUnit = {'Minutes' : 'min' , 'Seconds' : 's' , 'Milliseconds' : 'ms' , 'Microseconds' : 'us' }
45+
46+
4447# [INPUT Name:inputImagePath Type:string DisplayName:'Input Channel']
4548# [INPUT Name:scaleDirection Type:int DisplayName:'Down or Upscale (0 or 1)' Default:0 Min:0 Max:1]
4649# [INPUT Name:scaleFactorZ Type:double DisplayName:'Z scale factor' Default:1.0 Min:0.01 Max:20.0]
@@ -64,6 +67,13 @@ def run(params):
6467 Z_cal = float (pixel_cal [2 ].split (' ' )[0 ])
6568 T_cal = float (pixel_cal [3 ].split (' ' )[0 ])
6669
70+ # Check real calibration
71+ real_XYZ_calibration , real_T_calibration = False , False
72+ if not 'efault' in pixel_cal [0 ].split (' ' )[1 ]: # calibration ok
73+ real_XYZ_calibration = True
74+ if not 'efault' in pixel_cal [3 ].split (' ' )[1 ]: # calibration ok
75+ real_T_calibration = True
76+
6777 if not os .path .exists (image_location ):
6878 print (f"Error: { image_location } does not exist" )
6979 return
@@ -89,8 +99,8 @@ def run(params):
8999 scale_factor_z = scale_factor_z
90100
91101 # Calculating final pixel calibration
92- final_XY_cal = XY_cal / scale_factor_xy
93- final_Z_cal = Z_cal / scale_factor_z
102+ final_XY_cal = XY_cal / scale_factor_xy if real_XYZ_calibration else 1
103+ final_Z_cal = Z_cal / scale_factor_z if real_XYZ_calibration else 1
94104
95105 # Defining axes for output metadata and scale factor variable
96106 final_scale = None
@@ -123,17 +133,24 @@ def run(params):
123133 print ('img_as_ubyte' )
124134
125135 tmp_path = result_location .replace ('.tif' , '-scaled.tif' )
126- meta_info = {'axes' : axes , 'spacing' : str (final_Z_cal ), 'unit' : 'um' ,
127- 'TimeIncrement' : T_cal , 'TimeIncrementUnit' : 's' }
136+ meta_info = {'axes' : axes }
137+ if real_XYZ_calibration and zCount > 1 :
138+ meta_info .update ({'spacing' : str (final_Z_cal ), 'unit' : 'um' })
139+ if real_T_calibration :
140+ meta_info .update ({'TimeIncrement' : T_cal , 'TimeIncrementUnit' : IJTimeUnit [pixel_cal [3 ].split (' ' )[1 ]]})
128141
129142 # Formatting voxel calibration values
130143 inverted_XY_cal = 1 / final_XY_cal
131144 print (final_XY_cal )
132145
133146 print ('Saving image in temp location:\n ' , tmp_path )
134- imwrite (tmp_path , out_data , imagej = True , photometric = 'minisblack' , metadata = meta_info ,
135- resolution = (inverted_XY_cal , inverted_XY_cal ))
136-
147+ if real_XYZ_calibration :
148+ imwrite (tmp_path , out_data , imagej = True , photometric = 'minisblack' , metadata = meta_info ,
149+ resolution = (inverted_XY_cal , inverted_XY_cal ))
150+ else :
151+ # To avoid calibration in XYZ
152+ imwrite (tmp_path , out_data , imagej = True , photometric = 'minisblack' , metadata = meta_info )
153+
137154 # Dummy save
138155 dummy_data = np .zeros (image_data .shape , dtype = image_data .dtype )
139156 imwrite (result_location , dummy_data )
@@ -166,3 +183,4 @@ def run(params):
166183# v1_14: - Adding pixel/voxel calibration
167184# v1_20: - Adding time handling (but not rescale with time dimension)
168185# v1_30: - Fusing with parallel version updating aivia_path using new API params value
186+ # - Time increment is not recognized in Aivia at the moment
0 commit comments