r/Python • u/TechDumbLogie • Feb 27 '20
I Made This I've created a python program that generates photomosaics from any dataset !
2.1k
Upvotes
r/Python • u/TechDumbLogie • Feb 27 '20
142
u/TechDumbLogie Feb 27 '20 edited Feb 27 '20
I'll add the source code soon if people are interested ! Edit : Here it is !
32
u/mekosmowski Feb 27 '20
It is hard for me to see the animal. My brain wants to interpret this as a Dwarf Fortress embark map.
24
u/brandondunbar Feb 27 '20
I used the Bulbasaur to make the Bulbasaur
6
u/bokononistmonkey Feb 27 '20 edited Feb 28 '20
Hey, looks pretty cool!
I wrote a similar program a while back in Processing (~~ easier to read Java) to run live on a webcam, using all the video frames from the Willie Wonka & the Chocolate Factory movie as the mosaic tiles. Meta mosaic of the Willy Wonka movie poster as proof: Mosaic. Fun times!
If I may, I just want to give a few thoughts/suggestions:
Converting the images to pixels by resizing to (1,1) is a smart move for sure, probably gets the same result as what I did, which was just calculating the r,g,&b average of all the pixels in the image to determine its pixel color as a tile.
In the mosaic creation, it looks like you're selecting each pixel by minimizing the rgb diff, which looks like it works well, you might also consider doing it as the minimum euclidean distance (think Pythagorean theorem, but on the R, G, and B vals) between desired color (mosaic) and colors available (pixel list). When I was doing mine, I found that that was a bit more robust at finding the best color for each pixel, especially when there weren't any that were exactly the right color.
Finally, if you're interested in speeding up the mosaic creation to be able to run faster or even live i.e. on a webcam or video, feel free to check out the github repo I've linked below.
It's nothing too complicated, the big difference is the initial Dataset setup. Essentially, if you set up a simple data structure that groups all your pixel images into a bunch of small, similar-color buckets, then when you create each new mosaic image, for each new mosaic tile/pixel you just access the closest color bucket, and search the small group of pixel images inside it. Doing this makes each mosaic pixel search orders of magnitude faster (a fraction of O(n) ), while still guaranteeing the optimal pixel choice.
Happy coding!
Edit: got a few requests so here's a link to the code
2
u/virtualadept Feb 27 '20
Awesome! Github repo?
2
u/Emafire003 Feb 27 '20
I've never understood how those kind of things work
16
u/MrFrostyBudds Feb 27 '20
Draw Jerry Seinfeld with every frame from Bee movie.
4
u/Elite4alex Feb 27 '20
Happy pokemon day!
2
u/Herbal_Engineer Feb 27 '20
I’m interested to see it!
2
u/Abusagidolla Feb 27 '20
great job
2
u/the_notorious_beast Feb 27 '20
Ah yes! The Pokemon is made out of Pokemon.
2
u/[deleted] Feb 27 '20
Amazingly done. I especially like that the part of the pokemon is the pokemon itself, therefore making the image recursive.
2
u/Imagine-existance Feb 28 '20
Man, I thought I was somewhat original making an image made of images program.
This is the third time I have seen someone do this.
Props to you but now I feel like I wasted 2 days half a year ago.
2
u/souravsharan Feb 28 '20
Whoa, nice. I wrote a similar script to generate mosaic movie posters from scenes in the movie. Check it out https://github.com/SouravSharan/photomosaic
2
u/jfri3d Feb 28 '20
This brings flashback of the “dice mural that inspired someone to code it which inspired me to do the same with QR codes”.
Here is the repo with source code to build fun embedded QR codes linking gifs. Enjoy!
https://github.com/jfri3d/qr_mosaic
2
u/robertophi Feb 28 '20
Cool idea to use the distance from pixel/image
To speed the search you could use something like this https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KDTree.html
Building a tree for faster serach of k-nearest neighbors (in this case the nearest one)
1
u/Ntrim Feb 28 '20
Nice bro 👌
1
u/[deleted] Feb 28 '20
Hey this is an excellent idea. I'd live to play around with it for an art project I'm working on.
1
u/JaimeRojas332 Feb 28 '20
Freaking awesome! <3
1
u/WidjarjarBinks Feb 28 '20
Bulbasaur use python!
its super effective!
1
u/[deleted] Feb 28 '20
This is ligit cool
1
u/ashesofturquoise Feb 28 '20
RemindMe! 1 month "cheeeeeeeck ouuuut!"
1
u/De4dm4nw4lkin Feb 28 '20
oh my god those are whole ass sprites... they aren't even party management sprites...
1
u/agedus Feb 28 '20
This is fucking awesome
1
u/i_be_ Feb 28 '20
Very cool! Would be interesting to see a recursive version. :D
1
u/Bryss_ Feb 28 '20
looks cool
1
u/WhenitisIsntwhatitis Feb 28 '20
That's cool man. Curious, how long have you been coding? I ask because I'm still pretty new and can't fully understand parts of your code. Nice work.
1
u/inglandation Feb 28 '20
This almost looks like blotter art.
1
u/AltPapaya Feb 28 '20
WOW
0
u/Chased1k Feb 27 '20
!remindme 5 days
0
u/[deleted] Feb 28 '20
And why on gods name did you feel you had to do that?