Converting threshold image to binary data [closed]

asked 2014-01-19 08:03:43 -0500

Azwan gravatar image

updated 2014-01-19 09:03:49 -0500

I have a 19x19 image which have already been thresholded. now i need to read every pixel and determine if its black than output it as 1, if its white than output it as 0. please help ASAP. any help would be much appreciate.

Edited:

I need to output the binary to a text file

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2017-09-26 07:24:12.634798

Comments

1

why don't you threshold it to [0.1] in the 1st place ?

http://docs.opencv.org/java/org/opencv/imgproc/Imgproc.html#threshold(org.opencv.core.Mat,%20org.opencv.core.Mat,%20double,%20double,%20int)

berak gravatar imageberak ( 2014-01-19 08:10:52 -0500 )edit

What do you mean? does it directly threshold it to binary?

Azwan gravatar imageAzwan ( 2014-01-19 08:13:08 -0500 )edit

if you put 1 for 'maxValue' there, yes.

berak gravatar imageberak ( 2014-01-19 08:46:18 -0500 )edit

i did this:

Imgproc.threshold(picture1, picture2, 127, 1, THRESH_BINARY);

but then how do i save the text file?

Azwan gravatar imageAzwan ( 2014-01-19 08:54:51 -0500 )edit

sorry for the lack of details. i actually need to convert the threshold image as a binary value and save it to a text file

Azwan gravatar imageAzwan ( 2014-01-19 09:05:25 -0500 )edit
1

byte[] pixels = new bytes[19*19]; mat.get(0,0,pixels); then use a filestream or such to save the pixels

(why on gods earth do you need a txt file ?)

berak gravatar imageberak ( 2014-01-19 09:25:27 -0500 )edit

thank you. i will try that. i need the binary value for my own neural network text recognition input.

Azwan gravatar imageAzwan ( 2014-01-19 09:30:09 -0500 )edit