在Efford的cd中有一个灰度图像量化代码:
int n = 8 - numBits;//numBits will be taken as input
float scale = 255.0f / (255 >> n);
byte[] tableData = new byte[256];
for (int i = 0; i < 256; ++i)
tableData[i] = (byte) Math.round(scale*(i >> n));
LookupOp lookup =
new LookupOp(new ByteLookupTable(0, tableData), null);
BufferedImage result = lookup.filter(getSourceImage(), null);
return result;我试图转换此代码为24位彩色图像。但不知道我是否正确?
我的尝试: int = 24 - numBits;
float scale = 16777216.0f / (16777216 >> n);
byte[] tableData = new byte[16777216];
for (int i = 0; i < 16777216; ++i)
tableData[i] = (byte) Math.round(scale*(i >> n));
LookupOp lookup =
new LookupOp(new ByteLookupTable(0, tableData), null);
result = lookup.filter(img2, null);
//return result;这给出了结果,直到numBits>=17,如果numBits<17,那么我得到了完整的黑色图像。我做得对吗?
请帮帮忙。非常感谢。:)
发布于 2011-09-18 17:04:27
该代码只量化灰度图像,而不量化彩色图像。这意味着它一次只处理一个颜色通道。
此外,如果您正在执行24位-> 8位,您可能希望构造一个调色板,而不是简单的量化。
https://stackoverflow.com/questions/7462970
复制相似问题