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;
これにより、numBits> = 17までの結果が得られます。numBits <17の場合、完全な黒の画像が得られます。私はそれを正しくやっていますか?
助けてください。どうもありがとう。:)