Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please STOP writing per-pixel loops. you're shooting your own foot above with confusing x and y in multiple ways, and in general, the opencv way would be to use some existing higher level functions instead, like:

Mat im = imread("brain.png");
// make a mask, where everything white in the image is set to black
Mat mask; 
compare(im, Scalar::all(245), mask, CMP_GT);
// delete all pixels, where the mask is "off"
im.setTo(Scalar::all(0), mask);
imshow("B",im);

image description

please STOP writing per-pixel loops. you're shooting your own foot above with confusing x and y in multiple ways, and in general, the opencv way would be to use some existing higher level functions instead, like:

Mat im = imread("brain.png");
 // make a mask, where everything white in the image is set to black
Mat mask; 
compare(im, Scalar::all(245), mask, CMP_GT);
 // delete all pixels, where the mask is "off"
im.setTo(Scalar::all(0), mask);
 imshow("B",im);

image description