Error in changing the background color from white to black
hello. i am trying to change the background color to black. it's white so i am trying to go throught all the pixels and check whether its white or no if so change the value to 0. but somthing went wrong here is my code.
Mat img = imread("t.PNG");
for (int x = 0; x < img.rows; x++)
{
for (int y = 0; y < img.cols; y++)
{
if (img.at<Vec3b>(Point(x, y))[0] >=245 && img.at<Vec3b>(Point(x, y))[1] >= 245 && img.at<Vec3b>(Point(x, y))[2] >= 245)
{
img.at<Vec3b>(Point(x, y)) = { 0,0,0 };
}
}
}
imwrite("img.png",img);
imshow(" ",img);
waitKey(0);
Comments
- you seem to be lost about x,y, rows and cols. go over that again, and DON'T swap the semantics of it !
- don't write per-pixel loops, ever.
- what's the problem ? you forgot to mention !