Ask Your Question
0

Converting image from grayscale to binary

asked 2014-09-17 10:48:42 -0600

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?

edit retag flag offensive close merge delete

Comments

Can we convert back from binary to gray image ?

umang_bhatnagar gravatar imageumang_bhatnagar ( 2018-02-10 00:59:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-17 11:23:47 -0600

Haris gravatar image

updated 2014-09-17 11:24:29 -0600

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-17 10:48:42 -0600

Seen: 29,810 times

Last updated: Sep 17 '14