I would like to know how to convert an RGB image into a black & white (binary) image.
After conversion, how can I save the modified image to disk?
I would like to know how to convert an RGB image into a black & white (binary) image.
After conversion, how can I save the modified image to disk?
Simple binary threshold method is sufficient.
#include <string>
#include "opencv/highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("./img.jpg",0);//loading gray scale image
threshold(img, img, 128, 255, CV_THRESH_BINARY);//threshold binary, you can change threshold 128 to your convenient threshold
imwrite("./black-white.jpg",img);
return 0;
}
You can use GaussianBlur to get a smooth black and white image.