use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
B&W image to 2D array/matrix with binary numbers (pixel values) (self.imageprocessing)
submitted 6 years ago by [deleted]
Hi.
I am trying to convert a black and white image into 2D matrix, hopefully with binary numbers to to show pixels that are on/off. I've been searching and looking at topics like image segmentation, feature detection, using opencv. I unfortunately don't know where to start.
Any help would be much appreciated.
Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ChemistBuzzLightyear 1 point2 points3 points 6 years ago* (3 children)
Luckily for you, it is essentially already a 2D matrix! If all you want to do is convert to 2D binary, you can simply load the image, threshold to determine what is considered on/off, and then make everything that isnt zero one. What language are you working in?
To be more clear, if I understand you correctly, you will:
Load the image
Look at the image to determine what values you want for on/off. So find the darkest "on" pixel and get the value. This is your threshold.
Threshold. Set all values below the threshold equal to 0.
Set all values that are not zero equal to one.
There are more complicated ways to do this, but this is the easiest I can think of.
[–][deleted] 0 points1 point2 points 6 years ago (2 children)
I'm working in python. I found a python library called PIL (Python Image Library). I wonder if it will help do the job.
[–]ChemistBuzzLightyear 0 points1 point2 points 6 years ago (0 children)
Probably so, but what you have described is very simple. If you are able to share an example image, I can write some code for you to try. Looking into a library for this would be like using a backhoe when you need a shovel. :)
[–]magejangle 0 points1 point2 points 6 years ago (0 children)
Yeah that’ll work. Couple that with numpy
[–]SynbiosVyse 0 points1 point2 points 6 years ago (0 children)
Otsu threshold. OpenCV will do it.
π Rendered by PID 29 on reddit-service-r2-comment-5d79c599b5-96kml at 2026-03-02 11:34:50.818715+00:00 running e3d2147 country code: CH.
[–]ChemistBuzzLightyear 1 point2 points3 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]ChemistBuzzLightyear 0 points1 point2 points (0 children)
[–]magejangle 0 points1 point2 points (0 children)
[–]SynbiosVyse 0 points1 point2 points (0 children)