From 9649909c37bf4deeea2fda1e27ba461e2aed8fc4 Mon Sep 17 00:00:00 2001 From: Sami Date: Tue, 15 Jul 2025 15:09:50 +0100 Subject: [PATCH] fix: remove black stripe artefacts when axis != -1 in --- cellpose/transforms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cellpose/transforms.py b/cellpose/transforms.py index 16bfb0ae..13d5e2fd 100644 --- a/cellpose/transforms.py +++ b/cellpose/transforms.py @@ -765,10 +765,6 @@ def normalize_img(img, normalize=True, norm3D=True, invert=False, lowhigh=None, transforms_logger.critical(error_message) raise ValueError(error_message) - # Move channel axis back to the original position - if axis != -1 and axis != img_norm.ndim - 1: - img_norm = np.moveaxis(img_norm, -1, axis) - # The transformer can get confused if a channel is all 1's instead of all 0's: for i, chan_did_normalize in enumerate(cgood): if not chan_did_normalize: @@ -777,6 +773,10 @@ def normalize_img(img, normalize=True, norm3D=True, invert=False, lowhigh=None, if img_norm.ndim == 4: img_norm[:, :, :, i] = 0 + # Move channel axis back to the original position + if axis != -1 and axis != img_norm.ndim - 1: + img_norm = np.moveaxis(img_norm, -1, axis) + return img_norm def resize_safe(img, Ly, Lx, interpolation=cv2.INTER_LINEAR):