gpt4 book ai didi

algorithm - 我如何计算特征图中轻小簇的数量

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:07:29 26 4
gpt4 key购买 nike

假设我有这样的热图:

enter image description here

热图上像素的值范围为0-1。值越接近 0,像素越暗。上面有六个写簇,如图所示。有什么方法可以让我知道热图中有多少个光团?

最佳答案

来源 => 检测

enter image description here enter image description here


我的方法是:Gray => Threshold => FindContours(必要时按面积过滤)

#!/usr/bin/python3
# 2019/03/01
import cv2

img = cv2.imread("featmap.png")

# Gray => Threshold => FindContours (filter by area if necessary)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blured = cv2.medianBlur(gray, 3)
th, threshed = cv2.threshold(blured, 100, 255, cv2.THRESH_OTSU|cv2.THRESH_BINARY)
cnts = cv2.findContours(threshed, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[-2]

print("nums: {}".format(len(cnts)))

# draw on the original
cv2.drawContours(img, cnts, -1, (0, 255, 0), 1, cv2.LINE_AA)
cv2.imwrite("dst.png", img)

使用 findContours 时要小心:How to use `cv2.findContours` in different OpenCV versions?

关于algorithm - 我如何计算特征图中轻小簇的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54937750/

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