1 | initial version |
load the img into mat ..read the r g b s pixel wise ..and use the condition if (r == 0 && g == 255 && b == 0) to make that pixel to 0..You can change the logic according to ur img intensities.
cv::Mat img = cv::imread("inputPath");//3channel imagepath byte* img_ptr = (byte)img.data; int r, g, b; for (int y = 0; y < img.rows; y++) { for (int x = 0; x < img.cols; x++) { r = img_ptr[x * 3 + 2 + yimg.cols * 3]; g = img_ptr[x * 3 + 2 + yimg.cols * 3]; b = img_ptr[x * 3 + 2 + yimg.cols * 3];
if (r == 0 && g == 255 && b == 0)
{
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
}
}
}
cv::imwrite("outputPath", img);
img.release();
2 | No.2 Revision |
load the img into mat ..read the r g b s pixel wise ..and use the condition if (r == 0 && g == 255 && b == 0) to make that pixel to 0..You can change the logic according to ur img intensities.
{;
cv::Mat img = cv::imread("inputPath");//3channel imagepath
imagepath;
byte* img_ptr = (byte)img.data;
(byte*)img.data;
int r, g, b;
for (int y = 0; y < img.rows; y++)
{
for (int x = 0; x < img.cols; x++)
{
r = img_ptr[x * 3 + 2 + yimg.cols y*img.cols * 3];
g = img_ptr[x * 3 + 2 + yimg.cols g = img_ptr[x * 3 + 2 + y*img.cols * 3];
b = img_ptr[x * 3 + 2 + yimg.cols * 3];
b = img_ptr[x * 3 + 2 + y*img.cols * 3];
if (r == 0 && g == 255 && b == 0)
{
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
}
}
}
cv::imwrite("outputPath", img);
img.release();
}
3 | No.3 Revision |
load the img into mat ..read the r g b s pixel wise ..and use the condition if (r == 0 && g == 255 && b == 0) to make that pixel to 0..You can change the logic according to ur img intensities.
{;
cv::Mat img = cv::imread("inputPath");//3channel imagepath;
byte* img_ptr = (byte*)img.data;
int r, g, b;
for (int y = 0; y < img.rows; y++)
{
for (int x = 0; x < img.cols; x++)
{
r = img_ptr[x * 3 + 2 + y*img.cols * 3];
g = img_ptr[x * 3 + 2 1 + y*img.cols * 3];
b = img_ptr[x * 3 + 2 0 + y*img.cols * 3];
if (r == 0 && g == 255 && b == 0)
{
img_ptr[x * 3 + 2 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 1 + y*img.cols * 3]=0;
img_ptr[x * 3 + 2 0 + y*img.cols * 3]=0;
}
}
}
cv::imwrite("outputPath", img);
img.release();
}