[Android] add alpha channel to image

asked 2013-08-04 16:20:21 -0500

rahulbudhiraja gravatar image

updated 2013-08-04 16:21:37 -0500

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!

edit retag flag offensive close merge delete

Comments

why is the original image 16 channels? Where did it come from? Is something wrong with how it was saved?

xaffeine gravatar imagexaffeine ( 2013-08-05 12:45:34 -0500 )edit