Ask Your Question

How can i identify transparent and non-transparent pixel by iterating all pixels of bitmap in opencv(Java) android?

asked 2017-06-30 04:52:26 -0500

Aadhi gravatar image

I've a bitmap.Part of the bitmap is nontransparent and remaining transparent area. Using OpenCV Android Mat how can I identify nontransparent coordinates.?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-06-30 09:56:31 -0500

KjMag gravatar image

updated 2017-06-30 10:04:42 -0500

Mat m = imread("bitmap.bmp", IMREAD_UNCHANGED); // note the flag - necessary 
                                                     // for reading the alpha channel
List<Mat> channels = new ArrayList<Mat>(4);
Core.split(m, channels); // channels.get(3) is the alpha channel now
Mat transparent_coordinates = (channels.get(3) != 255);
Mat idx;

Transparent coordinates are going to be less than 255 for unsigned char and less than 1.0 for floating point pixels. If you want to detect only fully transparent pixels, the second line from the end should be:

Mat transparent_coordinates = (channels.get(3) == 0);

Now the idx object contains the coordinates of transparent pixels.

edit flag offensive delete link more


@KjMag, btw, nice, to have you here ;)

berak gravatar imageberak ( 2017-06-30 10:05:58 -0500 )edit

Thanks, nice to be here ;)

KjMag gravatar imageKjMag ( 2017-07-02 03:21:22 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-06-30 04:52:26 -0500

Seen: 2,406 times

Last updated: Jun 30 '17