I'm working with opencv for android studio. I have little experience with this, so I am asking for help to remove the background from the image and leave only the region of interest. I am working with images of wounds and I want to leave only the region of the wound on the application screen, as shown in the image below.
I am working with kotlin and I managed to perform the watershed of the image, just missing the region of the wound from the backgroung of the image, can someone help me?
private fun threashold(){
val width = imgBmpDefault?.getWidth()!!
val height = imgBmpDefault?.getHeight()!!
val rgba = Mat()
val gray_mat = Mat()
val threeChannel = Mat()
Utils.bitmapToMat(imgBmpDefault, gray_mat)
Imgproc.cvtColor(gray_mat, rgba, Imgproc.COLOR_RGBA2RGB)
Imgproc.cvtColor(rgba, threeChannel, Imgproc.COLOR_RGB2GRAY)
Imgproc.threshold(threeChannel, threeChannel, 100.0, 255.0, Imgproc.THRESH_OTSU)
val fg = Mat(rgba.size(), CvType.CV_8U)
Imgproc.erode(threeChannel, fg, Mat(), Point(-1.0, -1.0), 2)
val bg = Mat(rgba.size(), CvType.CV_8U)
Imgproc.dilate(threeChannel, bg, Mat(), Point(-1.0, -1.0), 3)
Imgproc.threshold(bg, bg, 1.0, 128.0, Imgproc.THRESH_BINARY_INV)
val markers = Mat(rgba.size(), CvType.CV_8U, Scalar(0.0))
Core.add(fg, bg, markers)
val marker_tempo = Mat()
markers.convertTo(marker_tempo, CvType.CV_32S)
Imgproc.watershed(rgba, marker_tempo)
marker_tempo.convertTo(markers, CvType.CV_8U)
imgBmpExit = Bitmap.createBitmap(width, height, Config.RGB_565)
Imgproc.applyColorMap(markers, markers, 4)
Utils.matToBitmap(markers, imgBmpExit)
imagem.setImageBitmap(imgBmpExit)
}
Exit using other image of wound: