Ask Your Question

Revision history [back]

OpenCV allows for easy indexation to create masks.

So imagine you want a cv::Mat with white pixels in the black zones of original image.

cv::Mat mask = cv::Mat::zeros(Original.size(), CV_8UC1);

mask.setTo(255, Original == 0);

Or

mask = (Original == 0);

This also works for > or < symbols, so, if you have

mask = (Original < 5);

Mask will have contain white pixels where Original has pixels lower than 5.

OpenCV allows for easy indexation to create masks.

So imagine you want a cv::Mat with white pixels in the black zones of original image.

cv::Mat mask = cv::Mat::zeros(Original.size(), CV_8UC1);

mask.setTo(255, Original == 0);

Or

mask = (Original == 0);

This also works for > or < symbols, so, if you have

mask = (Original < 5);

Mask will have contain contains white pixels where Original has pixels lower than 5.