簡體   English   中英

如何獲取多標簽閾值圖像的對象坐標

[英]How to get object coordinates of multilabel threshold image

我使用 cellpose 來分割我的圖像,現在想從標簽中提取對象坐標。 當使用image.shape查看返回的圖像時,我得到[img_length, img_width, 4] 我不太確定這是否是 CMYK 圖像。

我要回答的確切問題是如何從下圖中提取一個單元格的像素坐標(所以只有 1 個彩色斑點)?

在此處輸入圖像描述

好的,我設法解決了。

我遍歷圖像中的每個像素並保存顏色。 然后我使用 np.unique 來查找每個唯一的顏色值。

我刪除了包含背景的蒙版

然后我遍歷每種顏色並為圖像中的每種唯一顏色生成一個二進制掩碼並將其保存到單元格列表中。


color_array = np.empty((0, 4)) # 4 because I have four colour dimensions

        for x, y, *c in image[:, :, :]:
            color_array = np.append(color_array, c, axis = 0)

        unique_colours = np.unique(color_array, axis = 0).tolist()
        
        # Unique colours includes the background colour
        # I manually remove this colour from the list
        backg = [68,1,84,255] # This is the bg color given to cellpose images
        new_unique_colours = []

        for col in unique_colours:
            if col != backg:
                new_unique_colours.append(col)

        list_of_cells = []

        # Here I iterate through each colour to produce a binary mask of image for that colour

        for colour in new_unique_colours:
            single_cell = np.all(image == colour, axis=-1)
            list_of_cells.append(single_cell)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM