Ask Your Question

rahulbudhiraja's profile - activity

2019-09-05 14:01:04 -0600 received badge  Popular Question (source)
2014-05-22 06:45:05 -0600 received badge  Nice Question (source)
2013-08-04 17:19:19 -0600 received badge  Student (source)
2013-08-04 16:21:37 -0600 received badge  Editor (source)
2013-08-04 16:20:21 -0600 asked a question [Android] add alpha channel to image

Hi guys,

So I am trying to remove a particular color from an image and then save the modified image as a png .

Here's my code:

        Mat originalImage=Highgui.imread(picturePath);
        Log.d("channels","channels"+originalImage.channels()); // this gives out 16 .

        Mat bgra=new Mat(originalImage.cols(), originalImage.rows(),CvType.CV_16UC4);

        Imgproc.cvtColor(originalImage, bgra, Imgproc.COLOR_BGR2BGRA,4);
        Highgui.imwrite("/mnt/sdcard/test_transp.png", bgra); // this saves correctly too 

        Mat Mask=new Mat(originalImage.cols(), originalImage.rows(),CvType.CV_16UC4);

        Core.inRange(bgra, new Scalar(0,0,0),new Scalar(255,0,100), Mask);
        Highgui.imwrite("/mnt/sdcard/test.png", Mask); // black image ..even thought ther are portions which should be there after inRange

The problem is that the image is always a black image .I thought it was a colorspace issue and I have tried many variations like Imgproc.COLORRGB2BGRA etc but that did not work either.Any ideas what could possibly be the problem ?

Thanks!