我用疟疾扫描图像来分类是否有疟疾。数据集是从kaggle下载的。
我达到96%以上的准确度。
现在,我想知道如何检测扫描图像中的单元格。我需要指出图像中的疟疾细胞,或者画出疟疾细胞的轮廓。
含有疟疾细胞的样本图像

如何在这个问题上实现检测?
发布于 2020-02-17 20:28:35
如果我假设您想在图像中定位暗紫色,那么这是使用Python/OpenCV/Numpy/Sklearn进行定位的一种方法。
。
输入:

import cv2
import numpy as np
from sklearn import cluster
# read image
image = cv2.imread("purple_cell.png")
h, w, c = image.shape
# convert image to float in range 0-1 for sklearn kmeans
img = image.astype(np.float64)/255.0
# reshape image to 1D
image_1d = img.reshape(h*w, c)
# compute kmeans for 3 colors
kmeans_cluster = cluster.KMeans(n_clusters=3)
kmeans_cluster.fit(image_1d)
cluster_centers = kmeans_cluster.cluster_centers_
cluster_labels = kmeans_cluster.labels_
# need to scale back to range 0-255
newimage = (255*cluster_centers[cluster_labels].reshape(h, w, c)).clip(0,255).astype(np.uint8)
# Set BGR color ranges
lowerBound = np.array([170,90,120]);
upperBound = np.array([195,110,140]);
# Compute mask (roi) from ranges in dst
thresh = cv2.inRange(newimage, lowerBound, upperBound);
# get largest contour and all contours
contours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]
area_thresh = 0
result1 = image.copy()
for c in contours:
cv2.drawContours(result1, [c], -1, (0, 255, 0), 1)
area = cv2.contourArea(c)
if area > area_thresh:
area_thresh=area
big_contour = c
# draw largest contour only
result2 = image.copy()
cv2.drawContours(result2, [big_contour], -1, (0, 255, 0), 1)
cv2.imshow('image', image)
cv2.imshow('newimage', newimage)
cv2.imshow('thresh', thresh)
cv2.imshow('result1', result1)
cv2.imshow('result2', result2)
cv2.waitKey()
cv2.imwrite('purple_cell_kmeans_3.png', newimage)
cv2.imwrite('purple_cell_thresh.png', thresh)
cv2.imwrite('purple_cell_extracted1.png', result1)
cv2.imwrite('purple_cell_extracted2.png', result2)K手段图像:

缩影图像:

所有轮廓图像:

最大轮廓图像:

https://stackoverflow.com/questions/60267949
复制相似问题