Java Code Examples for android.support.v8.renderscript.ScriptIntrinsicConvolve3x3#setInput()

The following examples show how to use android.support.v8.renderscript.ScriptIntrinsicConvolve3x3#setInput() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSBox3x3Blur.java    From BlurView with Apache License 2.0 6 votes vote down vote up
@Override
public Bitmap blur(int radius, Bitmap bitmapOriginal) {
    radius = Math.min(radius,25);

    Allocation input = Allocation.createFromBitmap(rs, bitmapOriginal);
    final Allocation output = Allocation.createTyped(rs, input.getType());
    final ScriptIntrinsicConvolve3x3 script = ScriptIntrinsicConvolve3x3.create(rs, Element.U8_4(rs));
    script.setCoefficients(BlurKernels.BOX_3x3);
    for (int i = 0; i < radius; i++) {
        script.setInput(input);
        script.forEach(output);
        input = output;
    }
    output.copyTo(bitmapOriginal);
    return bitmapOriginal;
}
 
Example 2
Source File: Convolve.java    From easyrs with MIT License 5 votes vote down vote up
@Override
public void runConvolveScript(RSToolboxContext rsToolboxContext, Allocation aout, ConvolveParams scriptParams) {
    ScriptIntrinsicConvolve3x3 convolve3x3Script = ScriptIntrinsicConvolve3x3.create(
            rsToolboxContext.rs, rsToolboxContext.ain.getElement());
    convolve3x3Script.setInput(rsToolboxContext.ain);
    convolve3x3Script.setCoefficients(scriptParams.coefficients);
    convolve3x3Script.forEach(aout);
}
 
Example 3
Source File: ConvolveTest.java    From easyrs with MIT License 5 votes vote down vote up
@NonNull
private Bitmap getExpectedBitmap3x3(RenderScript rs, Bitmap bmpFromNv21) {
    Allocation ain = Allocation.createFromBitmap(rs, bmpFromNv21);
    Allocation aout = Allocation.createTyped(rs, ain.getType());

    ScriptIntrinsicConvolve3x3 convolve3x3Script = ScriptIntrinsicConvolve3x3.create(rs, ain.getElement());
    convolve3x3Script.setInput(ain);
    convolve3x3Script.setCoefficients(SampleParams.Convolve.Kernels3x3.SOBEL_X);
    convolve3x3Script.forEach(aout);

    Bitmap expectedBitmap = Bitmap.createBitmap(bmpFromNv21.getWidth(), bmpFromNv21.getHeight(), bmpFromNv21.getConfig());
    aout.copyTo(expectedBitmap);
    return expectedBitmap;
}
 
Example 4
Source File: FastStyleModelTiled.java    From style-transfer with Apache License 2.0 4 votes vote down vote up
public Bitmap processImage(Bitmap bitmap) {
    ScriptC_network script = new ScriptC_network(mRS);

    int numElements = 100;
    Element floatElement = Element.I32(mRS);
    Type arrayType = Type.createX(mRS, floatElement,  numElements);
    Allocation inputAlloc = Allocation.createTyped(mRS, arrayType);
    Allocation outputAlloc = Allocation.createTyped(mRS, arrayType);

    script.forEach_mapper(inputAlloc, outputAlloc);

    int[] output = new int[numElements];
    outputAlloc.copyTo(output);
    Log.i(TAG, output[0] + " " + output[99]);


    if (!mLoaded) {
        try {
            loadModel();
        } catch (IOException e) {

        }
    }
    int height = bitmap.getHeight();
    int width = bitmap.getWidth();

    // Crop the image.
    Bitmap outImgBig = Bitmap.createBitmap(bitmap, (width - MAX_IMG_SIZE) / 2,
            (height - MAX_IMG_SIZE) / 2, MAX_IMG_SIZE, MAX_IMG_SIZE);
    // Process the cropped image through the neural net.
    Allocation outImgBigAlloc = processImgChunk(outImgBig);

    // Blur the output image a bit.
    Allocation blurredAlloc = Allocation.createFromBitmap(mRS, outImgBig);
    ScriptIntrinsicBlur mBlur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS));
    mBlur.setInput(outImgBigAlloc);
    mBlur.setRadius(1.5f);
    mBlur.forEach(blurredAlloc);
    blurredAlloc.copyTo(outImgBig);

    // outImgBigAlloc.copyTo(outImgBig);
    ScriptIntrinsicConvolve3x3 convolution = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
    float[] matrix_sharpen =
                    { 0, -1, 0,
                     -1, 5, -1,
                      0, -1, 0};
    convolution.setInput(blurredAlloc);
    convolution.setCoefficients(matrix_sharpen);
    convolution.forEach(outImgBigAlloc);
    outImgBigAlloc.copyTo(outImgBig);

    logBenchmarkResult();
    return outImgBig;
}