0

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の場合、完全な黒の画像が得られます。私はそれを正しくやっていますか?

助けてください。どうもありがとう。:)

4

1 に答える 1

1

このコードは、カラー イメージではなく、グレースケール イメージのみを量子化します。これは、一度に 1 つのカラー チャネルのみを処理することを意味します。

また、24 ビット -> 8 ビットを実行している場合は、単純な量子化ではなく、パレットを作成する必要があります。

于 2011-09-18T17:04:27.863 に答える