我有一個二維共聚焦顯微鏡影像(二維切片)的 Z 堆疊,我想分割細胞。2D 影像的 Z 堆疊實際上是 3D 資料。在沿 Z 軸的不同切片中,我看到相同的單元格確實出現在多個切片中。我對 XY 中的單元格形狀感興趣,因此我想保留不同 Z 軸切片的最大單元格區域。我想在將它們轉換為標記的二進制影像后組合連續的 2D 切片,但我遇到的問題很少,我需要一些幫助才能進一步進行。
我有兩個影像img_a和img_b. 我首先使用 將它們轉換為二值影像OTSU,然后應用一些形態學運算,然后用于cv2.connectedComponentsWithStats()獲取標記物件。標記影像后,我將它們組合使用,cv2.bitwise_or()但它與標簽混淆。您可以在附加的處理影像中看到這一點(紅色圓圈突出顯示的單元格)。我看到重疊單元格的多個標簽。但是,我想為每個組合的重疊物件分配一個唯一標簽。
最后我想要的是,當我組合兩個帶標簽的影像時,我想為組合的重疊物件分配一個標簽(一個唯一值),并通過組合兩個影像來保持最大的單元格區域。有誰知道該怎么做?
這是代碼:
from matplotlib import pyplot as plt
from skimage import io, color, measure
from skimage.util import img_as_ubyte
from skimage.segmentation import clear_border
import cv2
import numpy as np
cells_a=img_a[:,:,1] # get the green channel
#Threshold image to binary using OTSU.
ret_a, thresh_a = cv2.threshold(cells_a, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU)
# Morphological operations to remove small noise - opening
kernel = np.ones((3,3),np.uint8)
opening_a = cv2.morphologyEx(thresh_a,cv2.MORPH_OPEN,kernel, iterations = 2)
opening_a = clear_border(opening_a) #Remove edge touchingpixels
numlabels_a, labels_a, stats_a, centroids_a = cv2.connectedComponentsWithStats(opening_a)
img_a1 = color.label2rgb(labels_a, bg_label=0)
## now do the same with image_b
cells_b=img_b[:,:,1] # get the green channel
#Threshold image to binary using OTSU.
ret_b, thresh_b = cv2.threshold(cells_b, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU)
# Morphological operations to remove small noise - opening
opening_b = cv2.morphologyEx(thresh_b,cv2.MORPH_OPEN,kernel, iterations = 2)
opening_b = clear_border(opening_b) #Remove edge touchingpixels
numlabels_b, labels_b, stats_b, centroids_b = cv2.connectedComponentsWithStats(opening_b)
img_b1 = color.label2rgb(labels_b, bg_label=0)
## Now combined two images
combined = cv2.bitwise_or(labels_a, labels_b) ## combined both labelled images to get maximum area per cell
combined_img = color.label2rgb(combined, bg_label=0)
plt.imshow(combined_img)
圖片可以在這里找到:
uj5u.com熱心網友回復:
根據 Christoph Rackwitz 和燒杯的評論,我開始四處尋找 3D 連接組件標簽。我找到了一個可以處理這些事情的 python 庫,我安裝了它并試一試。它似乎做得很好。它確實在每個切片中分配標簽,并為不同切片中的相同單元格保持標簽相同。這正是我想要的。
這是我用來標記 3D 物件的庫的鏈接。 https://pypi.org/project/connected-components-3d/
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/421080.html
標籤:
