Skip to content

Commit b8b8fda

Browse files
committed
In illumination correction, do not use hardcoded image size (ref #114)
1 parent b7fc222 commit b8b8fda

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

fractal/tasks/illumination_correction.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,34 @@ def illumination_correction(
137137
if not newzarrurl.endswith("/"):
138138
newzarrurl += "/"
139139

140-
# Hard-coded values for the image size
141-
# FIXME can we parse this from somewhere?
142-
img_size_y = 2160
143-
img_size_x = 2560
140+
# Read FOV ROIs
141+
FOV_ROI_table = ad.read_zarr(f"{zarrurl}tables/FOV_ROI_table")
142+
143+
# Read pixel sizes from zattrs file
144+
pixel_sizes_zyx = extract_zyx_pixel_sizes_from_zattrs(zarrurl + ".zattrs")
145+
146+
# Create list of indices for 3D FOVs spanning the entire Z direction
147+
list_indices = convert_ROI_table_to_indices(
148+
FOV_ROI_table,
149+
level=0,
150+
coarsening_xy=coarsening_xy,
151+
pixel_sizes_zyx=pixel_sizes_zyx,
152+
)
153+
154+
# Extract image size from FOV-ROI indices
155+
# Note: this works at level=0, where FOVs should all be of the exact same
156+
# size (in pixels)
157+
ref_img_size = None
158+
for indices in list_indices:
159+
img_size = (indices[3] - indices[2], indices[5] - indices[4])
160+
if ref_img_size is None:
161+
ref_img_size = img_size
162+
else:
163+
if img_size != ref_img_size:
164+
raise Exception(
165+
"ERROR: inconsistent image sizes in list_indices"
166+
)
167+
img_size_y, img_size_x = img_size[:]
144168

145169
# Load paths of correction matrices
146170
with open(path_dict_corr, "r") as jsonfile:
@@ -193,20 +217,6 @@ def illumination_correction(
193217
f"Error in illumination_correction, chunks_x: {chunks_x}"
194218
)
195219

196-
# Read FOV ROIs
197-
FOV_ROI_table = ad.read_zarr(f"{zarrurl}tables/FOV_ROI_table")
198-
199-
# Read pixel sizes from zattrs file
200-
pixel_sizes_zyx = extract_zyx_pixel_sizes_from_zattrs(zarrurl + ".zattrs")
201-
202-
# Create list of indices for 3D FOVs spanning the entire Z direction
203-
list_indices = convert_ROI_table_to_indices(
204-
FOV_ROI_table,
205-
level=0,
206-
coarsening_xy=coarsening_xy,
207-
pixel_sizes_zyx=pixel_sizes_zyx,
208-
)
209-
210220
# Create the final list of single-Z-layer FOVs
211221
list_indices = split_3D_indices_into_z_layers(list_indices)
212222

fractal/tasks/lib_regions_of_interest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import pandas as pd
1010

1111

12-
def prepare_FOV_ROI_table(
13-
df: pd.DataFrame,
14-
) -> ad.AnnData:
12+
def prepare_FOV_ROI_table(df: pd.DataFrame) -> ad.AnnData:
1513

1614
for mu in ["x", "y", "z"]:
1715

0 commit comments

Comments
 (0)