如何使用图像处理分割木瓷砖?

问题描述 投票:0回答:1

我有一托盘木砖。瓷砖可以是白色或灰色。有图像示例:

.

我想实现图块区域的分割,所以我们看不到纸板部分。

我尝试过简单阈值、Otsu阈值、分水岭算法。可能是我应用错误,但我无法仅实现木瓷砖区域的分割。我应该尝试什么想法吗?

python opencv image-processing image-segmentation
1个回答
0
投票

分割图像的方法有多种。这是一片广阔的田野。

这里我认为你遇到了照明问题,图像的左侧部分比右侧部分亮,导致左侧的纸板与一些瓷砖相等。也许其他颜色通道可以帮助您,例如 HSV(或 HSL)或 LAB...

这可能对您有帮助:

import cv2 as cv
import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt

# Load the image
image = cv.imread('your_image')
# blur it
blurred = cv.GaussianBlur(image,(11,11),0)
hsv = cv.cvtColor(blurred, cv.COLOR_BGR2HSV)  # Convert to RGB format

#define lower and upper bounds.
grayLower = (30,   0, 130)  
grayUpper = (180,   80, 180)  
mask = cv.inRange(hsv, grayLower, grayUpper)
res = cv.bitwise_and(image, image, mask = mask)
plt.imshow(res)
plt.show()

代码来自:参考

代码创建一个蒙版,用于在 HSV 通道内部查找边界内的灰色颜色,然后使用该蒙版重新创建图像。

之后,使用其他操作(例如 findCountour 或形态学)可能很容易找到中间最大的矩形。

© www.soinside.com 2019 - 2024. All rights reserved.