Ask Your Question
0

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 -0600

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
1

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

KjMag gravatar image

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

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;
Core.findNonZero(transparent_coordinates,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

Comments

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

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

Thanks, nice to be here ;)

KjMag gravatar imageKjMag ( 2017-07-02 03:21:22 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 4,050 times

Last updated: Jun 30 '17