Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Making an image out of a string in python

I remember seeing a tutorial on OpenCV on making an imagine out of a multiline string.

Example :

"""
001000000
001000000
001000000
001000000
001000000
001000000
"""

That would produce a black pixel for every 0 in the string, and a white pixel for the 1s.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

like that

Please tell me if I can give you more information!

>Solution :

Put a NetPBM header on with width and height and you are pretty much there if you save this as image.pbmit will be viewable with GIMP, Photoshop, feh, eog etc:

P1
9 6
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0

enter image description here


Enlarge it to 100 pixels wide, invert and convert to PNG with ImageMagick like this:

magick image.pbm -negate -scale 100x result.png
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading