4 ms·
Python Code to Generate Fully Custom “Random” Static Images
- supakeen 8y agoWhy the use of two different random number generators and drawing these images one pixel at a time? Why not swap the entire image colorspace to black/white for black/white? Why the choice of using imageio to create the gif when Pillow (imported at the beginning) can already do that as well? These are questions that are discussable, maybe the author isn't yet very familiar with generating images :)
- nightcracker 8y agoI like the part where the author calls numpy.random.uniform(low=0.0, high=1.0, size=None), explicitly passing size=None. They have the parameter that they want to immediately generate the entire image in one shot, and proceed to ignore it to generate the image pixel by pixel.
- minimaxir 8y ago> Why the choice of using imageio to create the gif when Pillow (imported at the beginning) can already do that as well? Can Pillow generate GIFs from numpy matrices? I had a similar design decision and it seems like Pillow wanted PIL.Image only. I also went with imageio because it uses the rectangle trick to cut down on filesize. (not relevant if the image is 100% noise however)
- deleted 8y ago[deleted]
- yorwba 8y agoThe last time I used Pillow to create GIFs [1], I also noticed that the files aren't exactly small. But instead of using a different library, I simply optimized the generated GIFs using gifsicle [2]. [1] https://github.com/Yorwba/kanjivg-gif https://github.com/Yorwba/kanjivg-gif [2] https://www.lcdf.org/gifsicle/ https://www.lcdf.org/gifsicle/
- dr_zoidberg 8y agoI abandoned PIL/Pillow a couple of years ago for OpenCV (a lot faster, and loads 16/32 bit int/float TIFs without problems), but I remember there were a couple of "utility functions" whose job was to translate from PIL.Image into a numpy.ndarray and back. I guess you'd convert every frame from the corresponding ndarray, and then save them into a list to build the GIF in memory.
- deleted 8y ago[deleted]
- monk_e_boy 8y agoWould this eventually produce all images? Including a photo of me. And the Queen nude, riding a dragon. All the worlds porn. A text description of GUT. And more.
- mdpopescu 8y agoNot in the lifetime of this universe.
- chillingeffect 8y agoIf you put some contact information in your profile I'd love to share with you a funny anecdote related to your comment. (Being of a purely humorous and whimsical nature, I'll respectfully decline from sharing it here as it doesn't fit the guidelines of HN.)
- dr_zoidberg 8y agoYou've caught my interest, and probably that of others who read your reply. Maybe it'd be easier to just share it with the community? If it doesn't go along the rules, we could simply ignore your comment, at worst downvote it or flag it, and that'd be it.
- monk_e_boy 8y agoI work in education, so sharing my contact info online is tricky for me :) children can be cunning
- autokad 8y agoI noticed in the bottom image, just by thinking about it you can 'make it' flow left, right, up, or down.
- techntoke 8y agoI have a script that does this: mpv --demuxer=rawvideo /dev/urandom