![](/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.