Ask Your Question
0

Converting image from grayscale to binary

asked Sep 17 '14

Rookie1 gravatar image

As you can see in the topic I want to convert simple image in grayscale that contains only black number/letter on white background to binary. I would want to set 0 where pixel is less than f.e. 100 and 255 where its greater than 100. Can you tell me how can I do it?

Preview: (hide)

Comments

Can we convert back from binary to gray image ?

umang_bhatnagar gravatar imageumang_bhatnagar (Feb 10 '18)edit

1 answer

Sort by » oldest newest most voted
1

answered Sep 17 '14

Haris gravatar image

updated Sep 17 '14

Just,

Convert source to GRAY using cvtColor()

Mat src= imread("src.jpg",1); // load source image
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY); //perform gray scale conversion.

Now threshold the image to get the desired result

threshold( gray, thr, 100,255,THRESH_BINARY );

You can start from tutorial page.

Preview: (hide)

Question Tools

Stats

Asked: Sep 17 '14

Seen: 30,205 times

Last updated: Sep 17 '14