Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
cv::Mat m = imread("bitmap.bmp", IMREAD_UNCHANGED); // note the flag - necessary 
                                                     // for reading the alpha channel
std::vector<cv::Mat> channels(4);
cv::split(m, channels); // channels[3] is the alpha channel now
cv::Mat transparent_coordinates = (channels[3] != 255);
cv::Mat idx;
cv::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:

 cv::Mat transparent_coordinates = (channels[3] == 0);

Now the idx object contains the coordinates of transparent pixels.

cv::Mat Mat m = imread("bitmap.bmp", IMREAD_UNCHANGED); // note the flag - necessary 
                                                     // for reading the alpha channel
std::vector<cv::Mat> List<Mat> channels(4);
cv::split(m, Core.split(m, channels); // channels[3] channels.get(3) is the alpha channel now
cv::Mat Mat transparent_coordinates = (channels[3] (channels.get(3) != 255);
cv::Mat Mat idx;
cv::findNonZero(transparent_coordinates,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:

 cv::Mat Mat transparent_coordinates = (channels[3] (channels.get(3) == 0);

Now the idx object contains the coordinates of transparent pixels.

Mat m = imread("bitmap.bmp", IMREAD_UNCHANGED); // note the flag - necessary 
                                                     // for reading the alpha channel
List<Mat> channels(4);
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.