gpt4 book ai didi

python - 在 Python 中使用 OpenCV 轮廓分析荧光细胞图像

转载 作者:行者123 更新时间:2023-12-02 16:13:52 25 4
gpt4 key购买 nike

我正在尝试使用 OpenCV 中的 Contours 来计算荧光细胞并计算总荧光面积。在探索了 Scikit Image 中的选项并尝试了 blob 检测之后,这似乎是我的图像类型最简单的方法。不幸的是,我似乎无法在细胞周围绘制轮廓。知道我做错了什么吗?

import cv2
import numpy as np

#import image
image = cv2.imread('Microcystis1.png')
cv2.imshow('image',image)
cv2.waitKey(0)

#Convert image to Grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('grayscale',gray)
cv2.waitKey(0)

#Threshold Binary
ret,thresh1 = cv2.threshold(gray,45,255,cv2.THRESH_BINARY)
cv2.imshow('binary',thresh1)
cv2.waitKey(0)

#Detect contours
contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)

#Draw contours
img = cv2.drawContours(thresh1, contours, -1, (0,255,0), 3)
cv2.imshow('contours',img)
cv2.waitKey(0)

#Analyze and Report Contours
cnt = contours[0]
area = cv2.contourArea(cnt)
print("Total Area: ", area)
print("Cell Count: ", len(cnt))
以下是图像的处理方式...
enter image description here
我的输出:
Total Area:  16.0
Cell Count: 14

最佳答案

你不需要得到轮廓。您可以在 Python/OpenCV 中简单地计算阈值图像中非零像素(白色像素)的数量。看

area = cv2.countNonZero(thresh)

https://docs.opencv.org/4.1.1/d2/de8/group__core__array.html#gaa4b89393263bb4d604e0fe5986723914

关于python - 在 Python 中使用 OpenCV 轮廓分析荧光细胞图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62722080/

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