【发布时间】:2020-07-03 20:07:03
【问题描述】:
我正在尝试使用 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))
这是处理图像的方式...
我的输出:
Total Area: 16.0
Cell Count: 14
【问题讨论】:
标签: python opencv image-processing contour