I loaded an image into a 2D array, where each index is a pixel. The image is just a white circle on black background.
I am having trouble locating the upper-most, left-most, right-most and bottom-most pixels of that circle.
Code:
// 255 = white, 0 = black
//left
if (circle[i][j] == 255 && circle[i-1][j] == 0 && circle[i][j-1] == 0)
cout << "left: " << i << "," << j << endl;
//right
if (circle[i][j] == 255 && circle[i-1][j] == 0 && circle[i][j+1] == 0)
cout << "right: " << i << "," << j << endl;
//up
if (circle[i][j] == 255 && circle[i-1][j] == 0 && circle[i][j-1] == 0)
cout << "up: " << i << "," << j << endl;
//down
if (circle[i][j] == 255 && circle[i+1][j] == 0 && circle[i][j-1] == 0)
cout << "down: " << i << "," << j << endl;
This is not working out for me, what would be the proper way to do this ?