使用颜色lut应用位图效果后如何避免噪音?

时间:2015-11-04 05:09:44

标签: android image filter bitmap lookup-tables

嗨我正在使用4x4颜色lut将效果应用于位图图像。在受影响的图像中应用但会产生一些噪点(图像中的阴影)。 如何避免这种噪音和图像质量也不见了?

我使用下面的代码来应用滤镜效果。

final static int X_DEPTH = 16;
final static int Y_DEPTH = 16; //One little square has 16x16 pixels in it 
final static int ROW_DEPTH = 4;
final static int COLUMN_DEPTH = 4; // the image consists of 4x4 little    squares
final static int COLOR_DISTORTION = 16; // 256*256*256 => 256 no distortion,    64*64*64 => 256 dividied by 4 = 64, 16x16x16 => 256 dividied by 16 = 16


private Bitmap applyLutToBitmap(Bitmap src, Bitmap lutBitmap) {

int lutWidth = lutBitmap.getWidth();
int lutColors[] = new int[lutWidth * lutBitmap.getHeight()];
lutBitmap.getPixels(lutColors, 0, lutWidth, 0, 0, lutWidth,   lutBitmap.getHeight());

int mWidth = src.getWidth();
int mHeight = src.getHeight();
int[] pix = new int[mWidth * mHeight];
src.getPixels(pix, 0, mWidth, 0, 0, mWidth, mHeight);

int R, G, B;
for (int y = 0; y < mHeight; y++)
    for (int x = 0; x < mWidth; x++) {
        int index = y * mWidth + x;
        int r = ((pix[index] >> 16) & 0xff) / COLOR_DISTORTION;
        int g = ((pix[index] >> 8) & 0xff) / COLOR_DISTORTION;
        int b = (pix[index] & 0xff) / COLOR_DISTORTION;

        int lutIndex = getLutIndex(lutWidth, r, g, b);

        R = ((lutColors[lutIndex] >> 16) & 0xff);
        G = ((lutColors[lutIndex] >> 8) & 0xff);
        B = ((lutColors[lutIndex]) & 0xff);
        pix[index] = 0xff000000 | (R << 16) | (G << 8) | B;
    }
Bitmap filteredBitmap = Bitmap.createBitmap(mWidth, mHeight, src.getConfig());
filteredBitmap.setPixels(pix, 0, mWidth, 0, 0, mWidth, mHeight);
return filteredBitmap;
}

//the magic happens here
private int getLutIndex(int lutWidth, int redDepth, int greenDepth, int    blueDepth) {
int lutX = (greenDepth % ROW_DEPTH) * X_DEPTH + blueDepth;
int lutY = (greenDepth / COLUMN_DEPTH) * Y_DEPTH + redDepth;
return lutY * lutWidth + lutX;
}
链接下面的

是我的lut,原始图片和过滤器影响的图片http://imgur.com/a/4BVio

请查看受影响的图像,受影响的图像中会出现一些噪点,图像质量也会丢失。如何使用4x4 lut来应用滤除滤镜效果而不会丢失图像质量?

0 个答案:

没有答案