【问题标题】:Smooth binary segmentation mask image in PythonPython中的平滑二值分割蒙版图像
【发布时间】:2020-09-25 09:57:31
【问题描述】:

我想平滑我的二进制图像分割掩码的轮廓,以改进我的卷积神经网络分割算法的输出。

我试过 PIL:

# Smooth the outline
from PIL import Image, ImageFilter
pil_img = Image.fromarray(orignal_mask)
smoothed_image = pil_img.filter(ImageFilter.SMOOTH)
smoothed_image = smoothed_image.filter(ImageFilter.SMOOTH_MORE)
smoothed_image_arr = np.array(smoothed_image)
smoothed_image_arr[smoothed_image_arr>=127] = 255
smoothed_image_arr[smoothed_image_arr<127] = 0
cv2.imwrite(data_dir + 'test_masks/smooth_{}'.format(jpg_filename), smoothed_image_arr)

阈值处理后,生成的图像看起来与原始蒙版基本相同。难道我做错了什么?有没有其他方法可以平滑二进制掩码?我愿意接受任何 Python 解决方案。

Original Jagged Binary Image Mask

【问题讨论】:

标签: python opencv image-processing python-imaging-library


【解决方案1】:

你可以尝试OpenCV应用形态学运算,开口可以稍微平滑边缘:

cv2.morphologyEx(mask, cv2.MORPH_OPEN,cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)))

【讨论】:

  • 请不要发帖duplicate answers。如果可以以某种方式回答两个问题,则问题是重复的。将一个标记为另一个的副本。
猜你喜欢
  • 2014-01-06
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 2020-09-23
  • 2020-01-31
  • 2014-10-15
  • 2021-10-06
  • 1970-01-01
相关资源
最近更新 更多