如下应用SLIC后如何检测云的百分比?

时间:2019-05-14 13:54:03

标签: python opencv

我需要计算云量的百分比。使用SLIC分割图像后如何计算?有人可以帮忙吗?

segments_slic = slic(img, n_segments=250, compactness=10, sigma=1)
print("Slic number of segments: %d" % len(np.unique(segments_slic)))

enter image description here

1 个答案:

答案 0 :(得分:2)

好吧,我认为您不需要为此应用SLIC。基本阈值可用于在灰度图像上找到云层覆盖的百分比,因为云层是白色的,并且像素值更大。

test image

我将此图像用作测试图像。

img = cv2.imread('cloud.png', 0)
ret, thresh = cv2.threshold(img, 100, 255, cv2.THRESH_BINARY)
cv2.imshow('image', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

这给

thresholded image

因此,我们需要将所有这些值加到有白色像素的地方,以找到白色像素的总数。而不是将阈值像素值更改为255,而是将其更改为1,以便我们可以简单地将它们相加。您可以在thresholding上阅读更多内容。然后,我们计算其总和,然后将其除以宽度和高度,再乘以100,以获得百分比。

img = cv2.imread('cloud.png', 0)
height = img.shape[0]
width = img.shape[1]
ret, thresh = cv2.threshold(img, 100, 1, cv2.THRESH_BINARY) 
total = sum(map(sum, thresh)) # to find total sum of 2D array thresh
percent = total/height/width*100
print('percentage of cloud cover is =', percent, '%')