My experiment drawing Mexico flag with thousands pictures
In February 23th, 2017, I was thinking in program something for giving honor to Mexico flag, since February 24th is the national day of the Mexico flag, "El día de la bandera" in spanish.
Since I like photography, I took around 23k pictures of my gallery, indexed them and make this picture.
Well, I chose Python language, it's the one I have more experience on. And decided to use "Pillow" library for image processing. The algorithm is like this...
What I did
Step 1. Create a new empty image 1280x1280 in memory. All will be drawn here.
Step 2. Create 3 different lists: green, white, red. This is for indexing images that are mostly those colors.
Step 3. Given a directory I iterate recursively. And save all the files path in a temporal database, so there's no need to walk directory tree everytime.
Step 4. I open each of the files. A counter for each color variation is taken in account: green, white, red.
Step 4 and one tenth. To compare each of the colors is like this
- green pixel when green > blue + 10 and green > red + 10
- white pixel when red > 190 and green > 190 and blue > 190
- red pixel when red > blue + 55 and red > g + 55
Step 4 and one fifth. After we complete iterating each pixel of the current image, we compare the counters of color similarities. If any of the counters counters are greater than the other two, that image will be considered redish, whiteish or greenish, and will be added respectively to its list, we continue to next image.
Step 5. Now we have a list of images that appears to be greenish, redish or whiteish.
Step 6. Iterating a virtual list of 3, where 0 is green, 1 is white and 2 is reddish, I put each of the image corresponding its color given an offset. I show the function.
And that's it, i run it
python mexico-flag.py
# I get the image in PNG format. The eagle was added in Photoshop.
You can look at the code here: https://github.com/gamikun/cosas-raras/blob/master/big-picture/mexico-flag.py
Some notes
- Lot of images are needed so images can be really found as mostly those colors.
- Small images are preferred for faster processing, I used the thumbnails of Apple Photos gallery.
- Process is heavy and takes too long.
- Image indexing is made one time, unless you delete the file db.data to reindex.
Thaks for reading and have a nice day.
Thank you for your contribution. This is a nice idea.
Lookingforward to your next contribution.
According to Utopian policies and guidelines, here are two important ones that you will not want to miss:
Happy New Year!
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Thank you for your review, @justyy! Keep up the good work!
hazme una foto curada de mi gato con muchas fotitos :V jajajaja se andaba usando hace uuuuu
te quedó curada
"foto con fotitos" aunque ese método era colorizar las fotos, con mi método se necesitan muchíiiisimas fotos y que coincidan con la tonalidad. 😎
Ingaturroña
Posted using Partiko Android
Congrats man!!! Viva México!😁🇲🇽🌶🌯🌮Feliz Año 2019🥂😉
Posted using Partiko Android
Feliz Año. Gracias por tu comentario. 😁
Invitación - @team-mexico
Canal Discord ¡Te esperamos!
Hola! @gama espero que la hayas pasado bien recibiendo este nuevo año! Te invito a compartir tu celebración en el Concurso de @anomadsoul @blocktrades echa un vistazo aqui:😉 https://steemit.com/steempress/@anomadsoul/contestmy2018welcomingthenewyear-100steeminprizes-mo805y48z7 Buena Suerte! Feliz 2019!😁🍀
Posted using Partiko Android
Congratulations @gama! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!