Images getting as too noise when applying filters

2019-06-04 02:11发布

I am developing an application which includes filters and crop too. Here I am using cropping library. Here I used 8*8 luts like sample lut. Here I want to CROP the filtered image(8*8 lut)

Here is the logic to crop the image.

Bitmap cropbitmap = ivCropimageView.getCroppedImage();

Using this bitmap I generate a thumbnail bitmap like below.

Bitmap thumbImage = ThumbnailUtils.extractThumbnail(cropbitmap, 190, 250);

When I am trying to generate thumbnails for all filters then the thumbnails are displaying as too noise like this.

This result is when I implemented the answer from renderscript.

So if anyone has ab idea please help me..

2条回答
再贱就再见
2楼-- · 2019-06-04 02:41

u can go through this, hope it will help you to get the right process.

photo is the main bitmap here.

mLut3D is the array of LUT images stored in drawable

    RenderScript mRs;
    Bitmap mLutBitmap, mBitmap;
    ScriptIntrinsic3DLUT mScriptlut;
    Bitmap mOutputBitmap;
    Allocation mAllocIn;
    Allocation mAllocOut;
    Allocation mAllocCube;
    int mFilter = 0;

mRs = RenderScript.create(yourActivity.this);
public Bitmap filterapply() {
        int redDim, greenDim, blueDim;
        int w, h;
        int[] lut;

        if (mScriptlut == null) {
            mScriptlut = ScriptIntrinsic3DLUT.create(mRs, Element.U8_4(mRs));
        }
         if (mBitmap == null) {
         mBitmap = photo;
}
        mOutputBitmap = Bitmap.createBitmap(mBitmap.getWidth(),
                mBitmap.getHeight(), mBitmap.getConfig());

        mAllocIn = Allocation.createFromBitmap(mRs, mBitmap);
        mAllocOut = Allocation.createFromBitmap(mRs, mOutputBitmap);
        // }

        mLutBitmap = BitmapFactory.decodeResource(getResources(),
                mLut3D[mFilter]);
        w = mLutBitmap.getWidth();
        h = mLutBitmap.getHeight();
        redDim = w / h;
        greenDim = redDim;
        blueDim = redDim;
        int[] pixels = new int[w * h];
        lut = new int[w * h];
        mLutBitmap.getPixels(pixels, 0, w, 0, 0, w, h);
        int i = 0;

        for (int r = 0; r < redDim; r++) {
            for (int g = 0; g < greenDim; g++) {
                int p = r + g * w;
                for (int b = 0; b < blueDim; b++) {
                    lut[i++] = pixels[p + b * h];
                }
            }
        }

        Type.Builder tb = new Type.Builder(mRs, Element.U8_4(mRs));
        tb.setX(redDim).setY(greenDim).setZ(blueDim);
        Type t = tb.create();
        mAllocCube = Allocation.createTyped(mRs, t);
        mAllocCube.copyFromUnchecked(lut);

        mScriptlut.setLUT(mAllocCube);
        mScriptlut.forEach(mAllocIn, mAllocOut);

        mAllocOut.copyTo(mOutputBitmap);
        return mOutputBitmap;
    }

you increase the mFilter value to get different filter effect with different LUT images, you have, check it out.

you can go through the this link on github for more help, i got the answer from here:- https://github.com/RenderScript/RsLutDemo

hope it will help

查看更多
仙女界的扛把子
3楼-- · 2019-06-04 03:03

I'm working on a LUT applier library which eases the use of LUT images in Android. Now it also guesses the color axes of the LUT:

https://github.com/dntks/easyLUT/wiki

It uses the algorythm I mentioned in the other post

查看更多
登录 后发表回答