Ask Your Question

Converting image from grayscale to binary

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

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


Can we convert back from binary to gray image ?

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

1 answer

Sort by ยป oldest newest most voted

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

Haris gravatar image

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


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
Login/Signup to Answer

Question Tools


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

Seen: 23,845 times

Last updated: Sep 17 '14