android - Removing white background image from Watershed mask -
I'm writing a sample using OpenSC's watershed algorithm. I am able to create a mask image, however, The mask has a white background rather than a transparent background. Is there a way to remove this white background and make it transparent? The code I am using is given below:
mat three channels = new mat (); Imgproke. CvtColor (cropimagamem, three channel, imgproc .color_BGR2GRAY); Imgroprop Thresholds (three channels, three channels, 100, 255, imgproke. DHRESH_BINARY | IMGproc.RERESH_OTSU); Mat fg = New mat (cropimage size (), CvType.CV_8U); Improprop .Road (three channels, FG, new matte), new point (-1, -1), 12); Mat BG = new mat (crop image size), CVTEPCV_8U); Imgropropilate (three channels, bg, new matte), new point (-1, -1), 12); Imgproke Threshold (BG, BG, 1, 128, IMGproc .THREHHINI) Mat markers = new mat (cropimage size (), cvttcv_8u, new scalar (0)); Cor.ed (FG, BG, Marker); WatershedsGeener Segment = New WatershedsGeener (); Segmenter.setMarkers (marker); Mat result = segmenter.process (croppedImageMat); Bitmap resultbm = bitmap.credbitmap (result.cols (), results. Cry (), bitmap config.argb_8888); Utils.matToBitmap (Results, Results Bmp); Constants.writeBitmapToFile (resultBmp); Public class watershedsgener {public mat marker = new mat (); Public Zero Set marker (mat mark image) {markerImage.convertTo (marker, CVType.CV_32S); } Public mat procedure (mat image) {Imgproke. Watershed (image, marker); Markers. Convertto (Marker, CvType.CV_8U); Return marker; }}
I want to create an image and create an image using the pocket mode of Android on the mask on an off-screen canvas. Please tell me if I am doing something wrong.
You can use the binary mask to get transparency effect.
Just use this mask to copy your piece in the background.
See the method A.copyTo (B, Mask);
If you want to get a quasi representative, you can use the equation
r = fg.mul (mask) + bg.mul (1.0-mask) ; FG - foreground image (CV_32 F1),
where
- Li> BG - background image ( CV_32 FC1),
- Mask - Transparency Layer (CV_32 FC1) value range must be [0.0; 1.0]
.
If you want to work with 3 channel pictures, use cv :: split metod, then process all the channels described above, combine the channels with the CV :: merge method. after.
Comments
Post a Comment