久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

計(jì)算圖像中的單元格數(shù)

Count number of cells in the image(計(jì)算圖像中的單元格數(shù))
本文介紹了計(jì)算圖像中的單元格數(shù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我需要計(jì)算圖像中細(xì)胞數(shù)量的代碼,并且只計(jì)算粉紅色的細(xì)胞.我使用了閾值法和分水嶺法.

I need code for counting the number of cells in the image and only the cells that are in pink color should be counted .I have used thresholding and watershed method.

import cv2
from skimage.feature import peak_local_max
from skimage.morphology import watershed
from scipy import ndimage
import numpy as np
import imutils

image = cv2.imread("cellorigin.jpg")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255,
    cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow("Thresh", thresh)


D = ndimage.distance_transform_edt(thresh)
localMax = peak_local_max(D, indices=False, min_distance=20,
    labels=thresh)
cv2.imshow("D image", D)

markers = ndimage.label(localMax, structure=np.ones((3, 3)))[0]
labels = watershed(-D, markers, mask=thresh)
print("[INFO] {} unique segments found".format(len(np.unique(labels)) -     1))

for label in np.unique(labels):
    # if the label is zero, we are examining the 'background'
    # so simply ignore it
    if label == 0:
        continue

    # otherwise, allocate memory for the label region and draw
    # it on the mask
    mask = np.zeros(gray.shape, dtype="uint8")
    mask[labels == label] = 255

    # detect contours in the mask and grab the largest one
    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
        cv2.CHAIN_APPROX_SIMPLE)
    cnts = imutils.grab_contours(cnts)
    c = max(cnts, key=cv2.contourArea)

    # draw a circle enclosing the object
    ((x, y), r) = cv2.minEnclosingCircle(c)
    cv2.circle(image, (int(x), int(y)), int(r), (0, 255, 0), 2)
    cv2.putText(image, "#{}".format(label), (int(x) - 10, int(y)),
        cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2)



cv2.imshow("input",image

cv2.waitKey(0)

我無(wú)法正確分割粉色單元格.在某些地方,兩個(gè)粉色單元格連接在一起,它們也應(yīng)該分開(kāi).

I am not able to segment the pink cells properly.At some places two pink cells are attached together those also should be separated.

輸出:

推薦答案

由于細(xì)胞的可見(jiàn)性似乎與細(xì)胞核(深紫色)和背景(淺粉色)不同,因此顏色閾值應(yīng)該在這里起作用.想法是將圖像轉(zhuǎn)換為 HSV 格式,然后使用上下顏色閾值來(lái)隔離細(xì)胞.這將為我們提供一個(gè)二進(jìn)制掩碼,我們可以使用它來(lái)計(jì)算單元格的數(shù)量.

Since the cells seem to be visibility different from the nucleus (dark purple) and the background (light pink), color thresholding should work here. The idea is to convert the image to HSV format then use a lower and upper color threshold to isolate the cells. This will give us a binary mask which we can use to count the number of cells.

我們首先將圖像轉(zhuǎn)換為 HSV 格式,然后使用較低/較高的顏色閾值來(lái)創(chuàng)建二進(jìn)制蒙版.從這里我們執(zhí)行形態(tài)學(xué)操作來(lái)平滑圖像并去除少量噪聲.

We begin by converting the image to HSV format then use a lower/upper color threshold to create a binary mask. From here we perform morphological operations to smooth the image and remove small bits of noise.

現(xiàn)在我們有了掩碼,我們使用 cv2.RETR_EXTERNAL 參數(shù)查找輪廓,以確保我們只獲取外部輪廓.我們定義了幾個(gè)區(qū)域閾值來(lái)過(guò)濾掉細(xì)胞

Now that we have the mask, we find contours with the cv2.RETR_EXTERNAL parameter to ensure that we only take the outer contours. We define several area thresholds to filter out the cells

minimum_area = 200
average_cell_area = 650
connected_cell_area = 1000

minimum_area 閾值確保我們不計(jì)算單元格的微小部分.由于一些單元格是連接的,一些輪廓可能有多個(gè)連接的單元格表示為單個(gè)輪廓,因此為了更好地估計(jì)單元格,我們定義了一個(gè) average_cell_area 參數(shù)來(lái)估計(jì)單個(gè)單元格的面積.connected_cell_area 參數(shù)檢測(cè)連接的單元格,其中在連接的單元格輪廓上使用 math.ceil() 來(lái)估計(jì)該輪廓中的單元格數(shù)量.為了計(jì)算單元格的數(shù)量,我們遍歷輪廓并根據(jù)它們的面積對(duì)輪廓求和.這是檢測(cè)到的以綠色突出顯示的單元格

The minimum_area threshold ensures that we do not count tiny sections of a cell. Since some of the cells are connected, some contours may have multiple connected cells represented as a single contour so to estimate the cells better, we define an average_cell_area parameter which estimates the area of a single cell. The connected_cell_area parameter detects connected cells where use math.ceil() on a connected cell contour to estimate the number of cells in that contour. To count the number of cells, we iterate through the contours and sum up the contours based on their area. Here's the detected cells highlighted in green

Cells: 75

代碼

import cv2
import numpy as np
import math

image = cv2.imread("1.jpg")
original = image.copy()
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)

hsv_lower = np.array([156,60,0])
hsv_upper = np.array([179,115,255])
mask = cv2.inRange(hsv, hsv_lower, hsv_upper)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)
close = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel, iterations=2)

cnts = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

minimum_area = 200
average_cell_area = 650
connected_cell_area = 1000
cells = 0
for c in cnts:
    area = cv2.contourArea(c)
    if area > minimum_area:
        cv2.drawContours(original, [c], -1, (36,255,12), 2)
        if area > connected_cell_area:
            cells += math.ceil(area / average_cell_area)
        else:
            cells += 1
print('Cells: {}'.format(cells))
cv2.imshow('close', close)
cv2.imshow('original', original)
cv2.waitKey()

這篇關(guān)于計(jì)算圖像中的單元格數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲高清视频在线 | 国产一区二区精品在线观看 | 欧美一区两区 | 国产精选一区 | 午夜影院在线免费观看视频 | 黄视频免费在线 | 亚洲 欧美 日韩 在线 | 91视频网址 | 国产九九九| 精品国产一区二区三区性色 | 国产一级在线 | 亚洲欧美在线观看 | 亚洲视频一区在线观看 | 亚洲自拍偷拍免费视频 | 日本不卡一区 | 国产视频福利一区 | 福利电影在线 | 91精品国产乱码久久久久久久久 | 亚洲成人精品久久 | 久久国产精品72免费观看 | 久久av一区二区三区 | 91在线观看网址 | 综合久久一区 | 福利片在线看 | 亚洲视频免费观看 | av一区二区三区四区 | 精品无码久久久久久国产 | 欧美二区在线 | 一道本在线 | 欧美国产日韩在线观看成人 | 夜夜夜夜夜夜曰天天天 | 欧美日日| 国产日韩欧美在线播放 | 高清视频一区二区三区 | 91视频在线观看 | 色本道 | 成人欧美一区二区三区黑人孕妇 | 久久91精品 | 99热国产精品 | 97免费视频在线观看 | 欧美日韩在线观看一区二区三区 |