I want to perform color reduction by scaling the color depth.
Like this example: 
the first image is CGA resolution, the second is EGA, and the third is HAM. I would like to do this with cv :: LUT, because I think it is better. I can do grayscale with this code:
Mat img = imread("test1.jpg", 0); uchar* p; Mat lookUpTable(1, 256, CV_8U); p = lookUpTable.data; for( int i = 0; i < 256; ++i) p[i] = 16 * (i/16) LUT(img, lookUpTable, reduced);
original: 
color reduced: 
but if I try to do this with color, I get a strange result.

using this code:
imgColor = imread("test1.jpg"); Mat reducedColor; int n = 16; for (int i=0; i<256; i++) { uchar value = floor(i/n) * n; cout << (int)value << endl; lut.at<Vec3b>(i)[2]= (value >> 16) & 0xff; lut.at<Vec3b>(i)[1]= (value >> 8) & 0xff; lut.at<Vec3b>(i)[0]= value & 0xff; } LUT(imgColor, lut, reducedColor);
nkint source share