![](/img/trans.png)
[英]How to get pixel coordinates of object after rendering the scene as image in pyrender?
[英]How to get object coordinates of multilabel threshold image
好的,我设法解决了。
我遍历图像中的每个像素并保存颜色。 然后我使用 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.