#๐Ÿ”’ OpenCV Mask Processing

5 messages ยท Page 1 of 1 (latest)

ember ibex
#

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?

icy daggerBOT
#

Hey @ember ibex!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
icy daggerBOT
#

@ember ibex

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

icy daggerBOT
#

@ember ibex

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.