0

I want to know how the number of colors are calculated in the following post:

How to reduce the number of colors in an image with OpenCV?

Liho has mentioned 27 and 125 colors in his comment. Please explain how he got these values. Thanks

Community
  • 1
  • 1
Navdeep
  • 823
  • 1
  • 16
  • 35

1 Answers1

1

Well its quite easy actually.

27 Colors - 3 Posibilities

  • R -> 3
  • G -> 3
  • B -> 3

3*3*3 = 27

125 Colors - 5 Possibilities

  • R -> 5
  • G -> 5
  • B -> 5

5*5*5 = 125

Luis Enrique
  • 440
  • 1
  • 4
  • 10
  • inline uchar reduceVal(const uchar val) { if (val < 64) return 0; if (val < 128) return 64; return 255; } – Navdeep Jul 24 '14 at 09:17
  • Liho Says that the image will be reduced to 27 colors using the above code . How? please explain. – Navdeep Jul 24 '14 at 09:18
  • @Navdeep An image in OpenCV is a Matrix, in this case there are 3 Matrices, one for each RGB channel, what he does is compare a pixel value and return a given value, so for all values between 0-63 you get 0, for values between 64-127 return 64, all other values return 255. Hence for each channel you will have 3 possible values, and 3x3x3 = 27 possible colors. Also, uchar is a byte so is between 0-255 – Luis Enrique Jul 24 '14 at 10:56