1

私は流域セグメンテーションを行っており、マーカー画像は距離変換を経たソース画像から派生しています。距離変換は浮動小数点画像を返します (ビット深度についてはわかりません)。32 ビットの単一チャネル画像が必要なため、流域メソッドを使用するのに問題があります。

マットの 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);
4

1 に答える 1

3

はい、convertTo 関数を使用して、任意の opencv マトリックスを別の型に変換できます。変換先の型は、同じサイズの宛先マトリックスに設定する必要があります。convertTo にはオプションのパラメーター scale と shift があるため、固定小数点深度に変換する際のクリッピングと量子化エラーを回避できます。だからあなたのコードのために:

Mat mDist32 = Mat(mDist.rows,mDist.cols,CV_32SC1); // 32 bit signed 1 channel, use CV_32UC1 for unsigned
mDist.convertTo(mDist32,CV_32SC1,1,0);
Imgproc.watershed(mThresh,mDist32);
于 2012-07-05T19:08:44.793 に答える