rockinfresh
rockinfresh

Reputation: 2106

Getting number of rows/columns from MAT Image

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): enter image description here

Upvotes: 3

Views: 4988

Answers (2)

skm
skm

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

Michael Burdinov
Michael Burdinov

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

Related Questions