mmsegmentation icon indicating copy to clipboard operation
mmsegmentation copied to clipboard

Palette is mapped to wrong object

Open jhaggle opened this issue 5 months ago • 0 comments

I have those classes and palette: classes = ('background', 'car', 'grass', 'person') palette = [[0, 0, 100], [255,0,0], [0,255, 0], [255,255,0]] # Blue, red, green, yellow

I then run this code to apply the palette to my images:

for file in mmengine.scandir(osp.join(data_root, ann_dir), suffix='.png'):
    seg_map = np.array(Image.open(osp.join(data_root, ann_dir, file)).convert('L'))
    seg_img = Image.fromarray(seg_map).convert('P')
    seg_img.putpalette(np.array(palette, dtype=np.uint8))
    seg_img.save(osp.join(data_root, new_dir, file))

However, the result is that the cars are green instead of red, the grass is yellow instead of green etc. How can this be fixed?

jhaggle avatar Jan 22 '24 13:01 jhaggle