Hacker News new | past | comments | ask | show | jobs | submit login
Python Code to Generate Fully Custom “Random” Static Images (github.com/christophershultz)
32 points by pplonski86 on Dec 26, 2018 | hide | past | favorite | 12 comments



Why 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 :)


I 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.


> 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)


I 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.


The 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

[2] https://www.lcdf.org/gifsicle/


I have a script that does this:

mpv --demuxer=rawvideo /dev/urandom


I noticed in the bottom image, just by thinking about it you can 'make it' flow left, right, up, or down.


Would 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.


Not in the lifetime of this universe.


If 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.)


You'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.


I work in education, so sharing my contact info online is tricky for me :) children can be cunning




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: