我正在开发一个应用程序来检测病变区域,为此我使用抓取来检测 ROI 并从图像中删除背景。但是,在某些图像中,它运行不佳。他最终没有很好地确定感兴趣区域的边界。分水岭可以更好地识别此类工作的边缘,但是我在从抓地到分水岭的过渡过程中遇到了困难。在处理抓取之前,用户使用 touchevent 在感兴趣的图像(伤口区域)周围标记一个矩形,以方便算法的工作。如下图。
但是,使用其他伤口图像,分割效果不佳,显示出 ROI 检测的缺陷。
在应用程序中使用抓取的图像
在桌面中使用分水岭的图像
这是代码:
private fun extractForegroundFromBackground(coordinates: Coordinates, currentPhotoPath: String): String {
// TODO: Provide complex object that has both path and extension
val width = bitmap?.getWidth()!!
val height = bitmap?.getHeight()!!
val rgba = Mat()
val gray_mat = Mat()
val threeChannel = Mat()
Utils.bitmapToMat(bitmap, gray_mat)
cvtColor(gray_mat, rgba, COLOR_RGBA2RGB)
cvtColor(rgba, threeChannel, COLOR_RGB2GRAY)
threshold(threeChannel, threeChannel, 100.0, 255.0, THRESH_OTSU)
val rect = Rect(coordinates.first, coordinates.second)
val fg = Mat(rect.size(), CvType.CV_8U)
erode(threeChannel, fg, Mat(), Point(-1.0, -1.0), 10)
val …
Run Code Online (Sandbox Code Playgroud)