text_plain_output_1.png
from PIL import Image

import matplotlib.patches as mpatches

import matplotlib.pyplot as plt

import mmcv

import numpy as np

import os.path as osp

import mmcv
import matplotlib.pyplot as plt
img = mmcv.imread('nails/images/2C29D473-CCB4-458C-926B-99D0042161E6.jpg')

import os.path as osp
import numpy as np
from PIL import Image
data_root = 'nails'
img_dir = 'images'
ann_dir = 'labels'
classes = ('background', 'nails')
palette = [[0, 0, 0], [225, 25, 38]]
for file in mmcv.scandir(osp.join(data_root, ann_dir), suffix='.jpg'):
    seg_img = Image.open(osp.join(data_root, ann_dir, file)).convert('P')
    seg_img.putpalette(np.array(palette, dtype=np.uint8))
    seg_img.save(osp.join(data_root, ann_dir, file.replace('.jpg', '.png')))

import matplotlib.patches as mpatches
img = Image.open('/content/mmsegmentation/nails/labels/09aefeec-e05f-11e8-87a6-0242ac1c0002.png')
plt.figure(figsize=(8, 6))
im = plt.imshow(np.array(img.convert('RGB')))
patches = [mpatches.Patch(color=np.array(palette[i]) / 255.0, label=classes[i]) for i in range(2)]
plt.legend(handles=patches, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.0, fontsize='large')
plt.show()