0

I have a bg removal model that takes in 512x512 RGB image and outputs a 512x512 Grayscale. How can i resize it back to original Widths and Heights, and invert this creepy Grayscale back to RGB?

 // Using here LiteRt support library for preprocessing
 val inputImageProcessor = ImageProcessor.Builder()
 .add(ResizeOp(512, 512, ResizeOp.ResizeMethod.NEAREST_NEIGHBOR))
 .build()
 val inputTensorImage = TensorImage(DataType.FLOAT32)
 inputTensorImage.load(bitmap)
 val processedInputImage = inputImageProcessor.process(inputTensorImage)
 val inputImageByteBuffer = processedInputImage.buffer
 // Creating Inputs for inference
 val image = TensorBuffer.createFixedSize(intArrayOf(1, 512, 512, 3), DataType.FLOAT32)
 image.loadBuffer(inputImageByteBuffer)
 val outputs = model.process(image)
 val masks = outputs.masksAsTensorBuffer
 // Trying to postprocess back and inverting, but with no results :(
 val outputImageProcessor = ImageProcessor.Builder()
 .add(ResizeOp(bitmap.height, bitmap.width, ResizeOp.ResizeMethod.BILINEAR))
 .build()
 val outputTensorImage = TensorImage(DataType.FLOAT32)
 outputTensorImage.load(segmentationMasks)
 val processedOutputImage = outputImageProcessor.process(outputTensorImage)
 val outputBitmap = processedOutputImage.bitmap
asked Jun 25, 2025 at 8:29

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.