gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:32 25 4
gpt4 key购买 nike

我需要计算云量的百分比。 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

最佳答案

嗯,我认为您不需要为此申请 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

因此我们需要在有白色像素的地方添加所有这些值以找到白色像素的总数。我们将阈值像素值改为 1,而不是 255,这样我们就可以简单地添加它们。您可以在 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, '%')

关于python - 如下应用 SLIC 后如何检测云的百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56132140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com