Making an image out of a string in python
Question:
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.
Please tell me if I can give you more information!
Answers:
Put a NetPBM header on with width and height and you are pretty much there if you save this as image.pbm
it 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
Enlarge it to 100 pixels wide, invert and convert to PNG with ImageMagick like this:
magick image.pbm -negate -scale 100x result.png
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.
Please tell me if I can give you more information!
Put a NetPBM header on with width and height and you are pretty much there if you save this as image.pbm
it 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
Enlarge it to 100 pixels wide, invert and convert to PNG with ImageMagick like this:
magick image.pbm -negate -scale 100x result.png