【问题标题】:Computer Vision: Improving Region of Interests segmentation计算机视觉:改进兴趣区域分割
【发布时间】:2021-08-05 01:51:32
【问题描述】:

我正在运行一个用于肺部区域分割的 x 射线上的 unet 模型,该模型似乎运行良好,但我的数据集不是很好看,我正在获得一些缺失部分的结果,如下所示:

我的问题是:是否有任何 cv 运算符我可以执行以使其更平滑以获得如下内容:

谢谢。

【问题讨论】:

  • 你的意思是dilation?
  • 谢谢,刚刚检查过了,在应用了一些腐蚀和膨胀之后,我得到了接近理想的结果。

标签: python numpy opencv computer-vision image-segmentation


【解决方案1】:

你描述的可以通过morphology实现。形态学操作是影响图像整体形状的一组(逻辑)操作。它可以“扩展”或“缩小”形状区域,以及许多其他 cool operations。

让我们使用膨胀来扩展图像的形状:

# Imports
import cv2
import numpy as np

# Read image
imagePath = "D://opencvImages//"
inputImage = cv2.imread(imagePath+"lungs.png")

# Convert BGR back to grayscale:
grayInput = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)

# Threshold via Otsu + bias adjustment:
threshValue, binaryImage = cv2.threshold(grayInput, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)

第一个位会将您发布的图像转换为二值图像,因为形态学运算只能在 1 通道图像(也是灰度)上执行,但由于我们将应用基本膨胀,因此二值图像就足够了。这是上面sn-p的结果:

让我们应用dilation。该操作可以连续应用,因此您可以指定多个iterations。既然你想要一个有点强烈的效果,让我们试试10 iterations。该操作需要名为“Structuring Element”(SE)的第二个操作数,它选择形状的已定义子区域中的像素。 SEs 有多种类型。最常见的一种是3 x 3rectangular SE:

# Set morph operation iterations:
opIterations = 10
# Set Structuring Element size:
structuringElementSize = (3, 3)
# Set Structuring element shape:
structuringElementShape = cv2.MORPH_RECT
# Get the Structuring Element:
structuringElement = cv2.getStructuringElement(structuringElementShape, structuringElementSize)

# Perform Dilate:
dilateImg = cv2.morphologyEx(binaryImage, cv2.MORPH_DILATE, structuringElement, None, None, opIterations, cv2.BORDER_REFLECT101)

# Show the image:
cv2.imshow("dilateImg", dilateImg)
cv2.waitKey(0)

这是结果:

【讨论】:

    猜你喜欢
    • 2014-12-03
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多