在 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 n = 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;
这会给出结果 inmage 直到 numBits>=17,如果 numBits<17 那么我得到完整的黑色图像。我做得对吗?
请帮忙。非常感谢。:)