繁体   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