If cellpose detects over 65,535 masks, images are cast to uint32 and then rescaled using cv2. However, this is interpreted as type CV_32S (signed integer as opposed to unsigned) by opencv which does not support unsigned 32-bit CV_32U (doc). cv2 does not support resizing images with type CV_32S (doc).
This behaviour is caused in dynamics.pyline 845, which casts to uint32 and is later resized in line 784.
Reproduce
Steps to reproduce the behavior in python 3.9.16, both on GPU and CPU
import numpy as np
import cv2
a = np.random.normal(size=(100, 200))
# SUCCEEDS: cast as unsigned int 8 bit
print(cv2.resize(a.astype(np.uint8), (50, 100)).shape)
# SUCCEEDS: cast as unsigned int 16 bit
print(cv2.resize(a.astype(np.uint16), (50, 100)).shape)
# FAILS: cast as unsigned int 32 bit
print(cv2.resize(a.astype(np.uint32), (50, 100)).shape)
This outputs the following log and error
(100, 50)
(100, 50)
---------------------------------------------------------------------------
error Traceback (most recent call last)
Cell In[75], line 13
10 print(cv2.resize(a.astype(np.uint16), (50, 100)).shape)
12 # FAILS: cast as unsigned int 32 bit
---> 13 print(cv2.resize(a.astype(np.uint32), (50, 100)).shape)
error: OpenCV(4.9.0) :-1: error: (-5:Bad argument) in function 'resize'
> Overload resolution failed:
> - src data type = uint32 is not supported
> - Expected Ptr<cv::UMat> for argument 'src'
System
opencv-python==4.9.0.80
numpy>=1.24.0
Full Error
Below is the complete output when running this code:
Description
If cellpose detects over 65,535 masks, images are cast to uint32 and then rescaled using cv2. However, this is interpreted as type
CV_32S
(signed integer as opposed to unsigned) by opencv which does not support unsigned 32-bitCV_32U
(doc). cv2 does not support resizing images with typeCV_32S
(doc).This behaviour is caused in
dynamics.py
line 845, which casts to uint32 and is later resized in line 784.Reproduce
Steps to reproduce the behavior in python 3.9.16, both on GPU and CPU
This outputs the following log and error
System
Full Error
Below is the complete output when running this code:
This yields the following log and output