Converting ARGB image with <256 Colours to single channel
Posted: 2014-09-22T14:19:26-07:00
I have a number of ARGB images (alpha will always be 0 or 1, and if required I can discard the alpha channel to have only RGB input.) Each image is guaranteed to have <255 unique colours in it.
I would like to convert these images to 8-bit single-channel (grayscale only) where each grayscale value represents a particular colour in the source image.
To be clear, this isn't just colour reduction, since I want to ensure that a different grayscale value is produced for the source RGB (0, 0, 255) vs (255, 0, 0). That is, the luminance of the colour should not determine wha the grayscale pixels' value is. Rather, each unique source colour should map to a single destination colour, *and vice-versa*.
However, I don't actually care WHAT colours are produced in the output L8 image, as long as they have unique 1:1 mapping to source colours. That is to say, they could simply be allocated starting from 1. In other words, rather than thinking in terms of colour-to-grayscale, the operation is more accurately like converting RGB colour to 8-bit RGB palletized, then replacing the palette entries with a grayscale ramp.
Any advice on how to achieve this would be greatly appreciated.
I would like to convert these images to 8-bit single-channel (grayscale only) where each grayscale value represents a particular colour in the source image.
To be clear, this isn't just colour reduction, since I want to ensure that a different grayscale value is produced for the source RGB (0, 0, 255) vs (255, 0, 0). That is, the luminance of the colour should not determine wha the grayscale pixels' value is. Rather, each unique source colour should map to a single destination colour, *and vice-versa*.
However, I don't actually care WHAT colours are produced in the output L8 image, as long as they have unique 1:1 mapping to source colours. That is to say, they could simply be allocated starting from 1. In other words, rather than thinking in terms of colour-to-grayscale, the operation is more accurately like converting RGB colour to 8-bit RGB palletized, then replacing the palette entries with a grayscale ramp.
Any advice on how to achieve this would be greatly appreciated.