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;

这会给出结果 inmage 直到 numBits>=17,如果 numBits<17 那么我得到完整的黑色图像。我做得对吗?

请帮忙。非常感谢。:)

4

1 回答 1

1

该代码仅量化灰度图像,而不量化彩色图像。这意味着它一次只处理一个颜色通道。

此外,如果你在做 24bit -> 8bit,你可能想要构建一个调色板而不是简单的量化。

于 2011-09-18T17:04:27.863 回答