'Unable to crop mask from original image
I'm trying to remove the background from an image. For that, I'm using TensorFlow which provides me mask of an object. After that, I'm cropping the mask from the image but the result is not as good as I wanted.
Using TensorFlow for masking:
https://github.com/tensorflow/examples/tree/master/lite/examples/image_segmentation/android
https://www.tensorflow.org/lite/examples/segmentation/overview
Cropping mask from the image.
fun bitmapDstIn(mask: Bitmap?, original: Bitmap?): Bitmap? {
return try {
val result =
original?.let { Bitmap.createBitmap(it.width, it.height, Bitmap.Config.ARGB_8888) }
val mCanvas = result?.let { Canvas(it) }
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
mask?.let { mCanvas?.drawBitmap(it, 0f, 0f, null) }
original?.let { mCanvas?.drawBitmap(it, 0f, 0f, paint) }
paint.xfermode = null
result
} catch (e: Exception) {
println(e.message.toString())
original
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

