Reputation: 2106
I was doing some plotting stuff when I realised that there was something wrong with my codes. So to do a test, while debugging, I tried to change all the pixels in the image into white.
Please view the code below. It should work right? I wrote this code in the past with no problem too. But... If you see the image below, not all the image become white. Only till less than half which is the "number of columns" but it's not suppose to be the case. Any idea why?
{
//uchar* z= image.data;
for (int i=0; i < image.rows; i++)
{
for (int j=0; j < image.cols; j++)
{
image.at<uchar>(i,j)= 255; //make all the pixels in the image white
}
}
cv::imshow("After",image);
}
RESULTS (see "after" window):
Upvotes: 3
Views: 4988
Reputation: 5679
You should do it in following way:
Vec3b intensity;
intensity.val[0] = 255;
intensity.val[1] = 255;
intensity.val[2] = 255;
for (int i=0; i < image.rows; i++)
{
for (int j=0; j < image.cols; j++)
{
image.at<Vec3b>(i,j)= intensity; //make all the pixels in the image white
}
}
cv::imshow("After",image);
}
Upvotes: 3
Reputation: 4448
You are working with color image which means that its size is 3*m*n bytes. You turned only first m*n pixels to white.
Upvotes: 3