I did this kind of image cropping from mask
mask = masks[0]
mask_uint8 = (mask * 255).astype(np.uint8)
#Morphology operations (Optional but recommended)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
mask_opened = cv2.morphologyEx(mask_uint8, cv2.MORPH_OPEN, kernel)
#Gaussian blur (Optional, adjust parameters as needed)
mask_blurred = cv2.GaussianBlur(mask_opened, (5, 5), sigmaX=2, sigmaY=2, borderType=cv2.BORDER_DEFAULT)
mask_binary = cv2.threshold(mask_blurred, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# Ensure correct data type (important after thresholding)
mask_binary = mask_binary.astype(np.uint8)
but why the cropping result still comes with a jagged pixel edge? anybody knows the root cause or solution that i could try?