OpenCV @Eliezer, .
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat3b img = imread("path_to_image");
Mat1b L(img.rows, img.cols, uchar(0));
for (int r = 0; r < img.rows; ++r)
{
for (int c = 0; c < img.cols; ++c)
{
Vec3b v = img(r,c);
L(r, c) = saturate_cast<uchar>((float(v[0]) + float(v[1]) + float(v[2])) / 3.f);
}
}
Mat1b L_blur;
medianBlur(L, L_blur, 11);
Mat1b mask;
threshold(L_blur, mask, 0, 255, THRESH_BINARY | THRESH_OTSU);
Mat3b output(img.rows, img.cols, Vec3b(0,0,0));
img.copyTo(output, mask);
imshow("Result", output);
waitKey();
return 0;
}
:
