You are accessing the elements of the matrix and you are accessing the image itself also. In your code, after you do this:
cv::Mat img = cv::imread("lenna.png");
the matrix img represents the image lenna.png. ( if it is successfully opened )
Why don't you experiment yourself by changing some of the pixel values:
cv::Mat img = cv::imread("lenna.png");
//Before changing
cv::imshow("Before",img);
//change some pixel value
for(int j=0;j<img.rows;j++)
{
for (int i=0;i<img.cols;i++)
{
if( i== j)
img.at<uchar>(j,i) = 255; //white
}
}
//After changing
cv::imshow("After",img);
Note: this only changes the image values in volatile memory, that is where the mat img is currently loaded. Modifying the values of the mat img, not going to change value in your actual image "lenna.png",which is stored in your disk, (unless you do imwrite)
But in case of 1-channel grayscale image it is CV_8UC1 not CV_32FC1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…