Mat image(5620, 4894, CV_16UC3, Scalar(0, 0, 0)); for (int j = 0; j < Change_Detected.rows; j++) { for (int l = 0; l < Change_Detected.cols; l++) { if (img.at<vec3b>(i,j)>200) { image.at<vec3b>(j, l)[0] = img.at<vec3b>(j, l)[0]; image.at<vec3b>(j, l)[1] = img.at<vec3b>(j, l)[1]; image.at<vec3b>(j, l)[2] = img.at<vec3b>(j, l)[2]; } } }