计算机视觉:改进兴趣区域分割

2024-04-26 03:33:36 发布

您现在位置:Python中文网/ 问答频道 /正文

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

enter image description here

我的问题是:是否有任何cv操作符可以预处理以使其更加平滑,从而获得如下结果:

enter image description here

谢谢


Tags: 数据模型unetcv射线区域分割肺部
1条回答
网友
1楼 · 发布于 2024-04-26 03:33:36

您描述的内容可以通过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)

第一位将您发布的图像转换为二值图像,因为形态学操作只能在单通道图像(也是灰度图像)上执行,但由于我们将应用基本膨胀,二值图像就足够了。这是上述代码片段的结果:

enter image description here

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

# 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)

结果是:

enter image description here

相关问题 更多 >