Images getting as too noise when applying filters in Android

白昼怎懂夜的黑 提交于 2019-12-08 05:41:49

问题


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..


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/33417152/images-getting-as-too-noise-when-applying-filters-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!