Single channel png displayed with colors

前端 未结 2 910
无人共我
无人共我 2020-12-19 11:53

I\'m checking out the ground truth segmentation masks of the pascal voc 2012 dataset. These are single channel 8-bit uint png files. However when I open these images in eith

2条回答
  •  庸人自扰
    2020-12-19 12:21

    You are dealing with an 1 to 8 bits (variable) per pixel PNG with indexed colors.

    When a format uses this technique, color information is not directly stored into the the image pixel data, but in a separate piece of data called palette. A palette can be defined as a predefined array of colors in which each element defines the trichromatic representation (RGB) of a specific color (8 bits per channel, for a total of 24 bits).

    The image pixel data does not contain the full specification of a color in the RGB form, but only the indices to the palette colors. Of course, the palette must contain one entry for each pixel color present in the image.

    This approach can be seen as a form of compression, in which only a limited set of colors is available in order to save up memory/storage and speed up the display of the image.

    Long story short, the result of your imread call is not returning you the color information of the image. Your array contains the indices to the PNG palette elements.

    Example

    Let's say that you have n indexed PNG that has a width of 3 pixels and a height of 1 pixel. The first pixel is pure red, the second pixel is pure green and the third pixel is pure blue.

    In the PNG binary data, the PLTE chunk will contain the following color definitions:

    [255 0 0] % Pure Red
    [0 255 0] % Pure Green
    [0 0 255] % Pure Blue
    

    and the IHDR chunk will define a single channel with the following data:

    0 1 2
    
    % 0 = index to the first palette color, pure red
    % 1 = index to the second palette color, pure green
    % 2 = index to the third palette color, pure blue
    

提交回复
热议问题