【发布时间】:2012-07-04 16:31:23
【问题描述】:
我正在进行分水岭分割,标记图像来自经过距离变换的源图像。距离变换返回一个浮点图像(我不知道位深度),我无法将其通过分水岭方法,因为它需要 32 位单通道图像。
我可以使用 mat 的 convertTo 方法将位深度设置为 32 吗? 我也很难显示浮点图像,因为 matToBitmap() 方法似乎不接受它们。 (在 Android 中)
Mat mImg = new Mat();
Mat mThresh = new Mat();
Mat mDist = new Mat();
ImageView imgView = (ImageView) findViewById(R.id.imageView);
Bitmap bmpIn = BitmapFactory.decodeResource(getResources(),
R.drawable.w1);
Utils.bitmapToMat(bmpIn, mImg);
Imgproc.cvtColor(mImg, mImg, Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(mImg, mThresh, 0, 255, Imgproc.THRESH_BINARY
| Imgproc.THRESH_OTSU);
//Marker image for watershed
Imgproc.distanceTransform(mThresh, mDist, Imgproc.CV_DIST_L2, Imgproc.CV_DIST_MASK_PRECISE);
//Conversions for watershed
Imgproc.cvtColor(mThresh, mThresh, Imgproc.COLOR_GRAY2BGR, 3);
//Floating-point image -> 32-bit single-channel
mDist.convertTo(...);
Imgproc.watershed(mThresh, mDist); //
Bitmap bmpOut = Bitmap.createBitmap(mThresh.cols(), mThresh.rows(),
Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mThresh, bmpOut);
imgView.setImageBitmap(bmpOut);
【问题讨论】:
-
OpenCV 中 32 位、单通道、浮点图像的类型代码是 CV_32FC1。转换为该类型有效吗?
标签: android image-processing opencv computer-vision