我有一个木砖托盘。瓷砖可以是白色或灰色。有图像的例子:
。我想实现瓷砖区域的分割,所以我们看不到纸板部分。我试过简单的阈值,大津阈值,分水岭算法。可能是我用错了,但我不能设法实现分割只有该地区的木制瓷砖。任何想法,我应该尝试?
gajydyqb1#
图像分割有多种方法,是一个广阔的领域。这里我认为你有一个lightining问题,图像的左边部分比右边部分亮,导致左边的纸板等于一些瓷砖。也许其他颜色通道可以帮助你,如HSV(或HSL)或LAB...这可以帮助您:
import cv2 as cvimport numpy as npfrom sklearn.cluster import KMeansimport matplotlib.pyplot as plt# Load the imageimage = cv.imread('your_image')# blur itblurred = 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()
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()
代码来源:reference代码创建一个遮罩,在HSV通道内查找边界内的灰色,然后使用该遮罩重新创建图像。在此之后,可以很容易地找到中间最大的矩形与其他操纵,如findCountour或形态。
1条答案
按热度按时间gajydyqb1#
图像分割有多种方法,是一个广阔的领域。
这里我认为你有一个lightining问题,图像的左边部分比右边部分亮,导致左边的纸板等于一些瓷砖。也许其他颜色通道可以帮助你,如HSV(或HSL)或LAB...
这可以帮助您:
代码来源:reference
代码创建一个遮罩,在HSV通道内查找边界内的灰色,然后使用该遮罩重新创建图像。
在此之后,可以很容易地找到中间最大的矩形与其他操纵,如findCountour或形态。