Skip to content

Refactor image conversion functions for improved clarity and error ha…#1183

Merged
mrariden merged 1 commit intomainfrom
3d_shape_fix
May 19, 2025
Merged

Refactor image conversion functions for improved clarity and error ha…#1183
mrariden merged 1 commit intomainfrom
3d_shape_fix

Conversation

@mrariden
Copy link
Copy Markdown
Collaborator

better tests for transforms to catch things we missed previously.

3d image reading fixes and explicit guessing about what the order is in the gui. API is more robust.

…ndling; add comprehensive tests for convert_image functionality.
@mrariden mrariden self-assigned this May 16, 2025
@mrariden
Copy link
Copy Markdown
Collaborator Author

full test passing on ubuntu

@mrariden
Copy link
Copy Markdown
Collaborator Author

mrariden commented May 16, 2025

gui appears to be working too

Guessing will fail for some images:

cellpose/cellpose/io.py

Lines 236 to 266 in 9cb3c29

def imread_3D(img_file):
"""
Read in a 3D image file and convert it to have a channel axis last. Attempts to do this for multi-channel and grayscale images.
Args:
img_file (str): The path to the image file.
Returns:
img_out (numpy.ndarray): The image data as a NumPy array.
"""
img = imread(img_file)
dimension_lengths = list(img.shape)
# guess at channel axis:
channel_axis = np.argmin(img.shape)
del dimension_lengths[channel_axis]
# guess at z axis:
z_axis = np.argmin(dimension_lengths)
# grayscale images:
if img.ndim == 3:
channel_axis = None
try:
return transforms.convert_image(img, channel_axis=channel_axis, z_axis=z_axis, do_3D=True)
except Exception as e:
io_logger.critical("ERROR: could not read file, %s" % e)
io_logger.critical("ERROR: Guessed z_axis: %s, channel_axis: %s" % (z_axis, channel_axis))
return None

@mrariden mrariden merged commit 3de72de into main May 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant