Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
int main (int argc, char** argv)
{

Mat img=imread("D:\\32.png",CV_LOAD_IMAGE_COLOR);
Mat A = Mat::zeros(img.size(),img.type());

namedWindow("Display window");

namedWindow("threshold");
imshow("Display window",img);
for (int i = 0; i < img.size().height; ++i)
{
for(int j = 0; j < img.size().width; ++j)
{   
A.at<Vec3b>(i,j) = img.at<Vec3b>(i,j);


    }
}
imwrite("D:\\etc1.png",A);
imshow("threshold",A);
waitKey(0);

}

Below code work for me on your image

int main (int argc, char** argv)
{

Mat img=imread("D:\\32.png",CV_LOAD_IMAGE_COLOR);
Mat A = Mat::zeros(img.size(),img.type());

namedWindow("Display window");

namedWindow("threshold");
imshow("Display window",img);
for (int i = 0; i < img.size().height; ++i)
{
for(int j = 0; j < img.size().width; ++j)
{   
A.at<Vec3b>(i,j) = img.at<Vec3b>(i,j);


    }
}
imwrite("D:\\etc1.png",A);
imshow("threshold",A);
waitKey(0);

}

input image

image description

output image

image description

Below code work for me on your imageimage , it looks your performing which are not compulsory to perform in copying image using pixel operation

int main (int argc, char** argv)
{

Mat img=imread("D:\\32.png",CV_LOAD_IMAGE_COLOR);
Mat A = Mat::zeros(img.size(),img.type());

namedWindow("Display window");

namedWindow("threshold");
imshow("Display window",img);
for (int i = 0; i < img.size().height; ++i)
{
 for(int j = 0; j < img.size().width; ++j)
 {   
 A.at<Vec3b>(i,j) = img.at<Vec3b>(i,j);
     }
}
imwrite("D:\\etc1.png",A);
imshow("threshold",A);
waitKey(0);

}

input image

image description

output image

image description

Below code work for me on your image , it looks your performing functions which are not compulsory to perform in copying image using pixel operation

int main (int argc, char** argv)
{

Mat img=imread("D:\\32.png",CV_LOAD_IMAGE_COLOR);
Mat A = Mat::zeros(img.size(),img.type());

namedWindow("Display window");

namedWindow("threshold");
imshow("Display window",img);
for (int i = 0; i < img.size().height; ++i)
{
  for(int j = 0; j < img.size().width; ++j)
    {   
       A.at<Vec3b>(i,j) = img.at<Vec3b>(i,j);
    }
}
imwrite("D:\\etc1.png",A);
imshow("threshold",A);
waitKey(0);

}

input image

image description

output image

image description