Skip to content

Commit

Permalink
In illumination correction, do not use hardcoded image size (ref #114)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Jul 22, 2022
1 parent b7fc222 commit b8b8fda
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
46 changes: 28 additions & 18 deletions fractal/tasks/illumination_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,34 @@ def illumination_correction(
if not newzarrurl.endswith("/"):
newzarrurl += "/"

# Hard-coded values for the image size
# FIXME can we parse this from somewhere?
img_size_y = 2160
img_size_x = 2560
# Read FOV ROIs
FOV_ROI_table = ad.read_zarr(f"{zarrurl}tables/FOV_ROI_table")

# Read pixel sizes from zattrs file
pixel_sizes_zyx = extract_zyx_pixel_sizes_from_zattrs(zarrurl + ".zattrs")

# Create list of indices for 3D FOVs spanning the entire Z direction
list_indices = convert_ROI_table_to_indices(
FOV_ROI_table,
level=0,
coarsening_xy=coarsening_xy,
pixel_sizes_zyx=pixel_sizes_zyx,
)

# Extract image size from FOV-ROI indices
# Note: this works at level=0, where FOVs should all be of the exact same
# size (in pixels)
ref_img_size = None
for indices in list_indices:
img_size = (indices[3] - indices[2], indices[5] - indices[4])
if ref_img_size is None:
ref_img_size = img_size
else:
if img_size != ref_img_size:
raise Exception(
"ERROR: inconsistent image sizes in list_indices"
)
img_size_y, img_size_x = img_size[:]

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

# Read FOV ROIs
FOV_ROI_table = ad.read_zarr(f"{zarrurl}tables/FOV_ROI_table")

# Read pixel sizes from zattrs file
pixel_sizes_zyx = extract_zyx_pixel_sizes_from_zattrs(zarrurl + ".zattrs")

# Create list of indices for 3D FOVs spanning the entire Z direction
list_indices = convert_ROI_table_to_indices(
FOV_ROI_table,
level=0,
coarsening_xy=coarsening_xy,
pixel_sizes_zyx=pixel_sizes_zyx,
)

# Create the final list of single-Z-layer FOVs
list_indices = split_3D_indices_into_z_layers(list_indices)

Expand Down
4 changes: 1 addition & 3 deletions fractal/tasks/lib_regions_of_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import pandas as pd


def prepare_FOV_ROI_table(
df: pd.DataFrame,
) -> ad.AnnData:
def prepare_FOV_ROI_table(df: pd.DataFrame) -> ad.AnnData:

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

Expand Down

0 comments on commit b8b8fda

Please sign in to comment.