Mapping between RGB colors and material annotations
maheshkkumar opened this issue · comments
Mahesh Reddy commented
Hi Lukas,
Thank you for creating this interesting dataset.
I was able to find the material map numbers from #4, but I was unable to find information regarding the mapping between these material annotations to the corresponding RGB color palette in the material segmentation maps. Could you please provide this information?
Thanks,
Mahesh
Lukas Murmann commented
The mappings are embedded as a palette inside the PNG file. This functions reads the image using Pillow and optionally replaces the 1D index with 3D colors (see query_materials
function
def readpng_indexed(path, *, apply_palette):
"""Indexed PNG read helper. Requires PIL."""
from PIL import Image
im = Image.open(path)
if not im.mode == "P":
raise ValueError("Expected indexed PNG")
if apply_palette:
im = im.convert(mode="RGB")
shape = (im.height, im.width, 3)
else:
shape = (im.height, im.width)
npim = np.ndarray(shape=shape, dtype="uint8", buffer=im.tobytes())
# palette = np.ndarray(shape=[256,3], dtype="uint8", buffer=im.palette.getdata()[1])
return npim
You can use the
palette = np.ndarray(shape=[256,3], dtype="uint8", buffer=im.palette.getdata()[1])
line to access the palette as a numpy array.
Mahesh Reddy commented
Thanks for your quick response.