0

I am working on C# Emgu CV to convert 256 color image to 16 color image.

I could read the image data.

Image<Gray, Byte> img = new Image<Gray, Byte>("test01.bmp");

I can find the convert function.

Image<Gray, Byte> img2 = img.Convert(Gray, Byte);

Here, the second parameter is Depth of the image. I want to set it as 4. But the available values of the parameters are like below.

Byte, SByte, Single, double, UInt16, Int16 or Int32

How can I solve this problem?

Blake
  • 259
  • 5
  • 23

1 Answers1

0

In the example you have given you are converting the color image into a gray scale image. A gray scale image is NOT a 256 color image. A 256 color image uses a unsigned byte as an index into a color palette. A 16 color image only needs 4 bits to provide the index into a 16 color palette. I suspect that a 16 color image would still have each pixel represented by the lower 4-bits of an unsigned byte. It is possible to pack 2 pixels into a single byte but I do not know of any systems that do this.

The bottom line is you do not want to set the depth of the converted image to 4, you want to use Byte, since a 256 color image needs 8 bits. There is no routine in EmguCV that I am aware of that will convert a 256 color image into a 16 color image.

If you are not a color palette then you will need to quantize the image. There are a number of good articles on this process. This contains some very good examples.

Doug

AeroClassics
  • 1,074
  • 9
  • 19