Za Mozaiku
can create a photo mosaic of an image, using a YouTube url, a video or a folder of images.
Although it may be slow depending on various things, such as the size of the output image, the number of steps or the length of the video, it’s really easy to use.
to install only the mozaiku
package run in your terminal to download the latest stable version
pip install mozaiku
otherwise you can also download it from GitHub, but it may contain untested code
pip install git+https://github.com/Zslez/Mozaiku.git
if you need also youtube-dl
features, install it running the command
pip install -U youtube-dl
To install ffmpeg
you can go to this page and download it there, however if you're not on Windows, you should be able to install it using your package manager in your terminal.
Note however that I haven't tested it on other operating systems yet. See tests for more informations.
NOTE:
mozaiku.from_video()
skips step 1mozaiku.from_folder()
skips step 1 and 2
STEPS:
- DOWNLOAD VIDEO
using
youtube-dl
, it downloads the video from the given YouTube url
- EXTRACT FRAMES
using
ffmpeg
, it splits the video fromstep 1
into all its frames, using the givenfps
value as frame rate, and saves those frames in a folder
- GET NEEDED FRAMES
it loops through all the frames in the folder, resizes them according to the
frames_size
value, crops them to square, and saves their average color in a dictionary removing duplicates
- GENERATE NEW IMAGE STRUCTURE
it opens the input image and resizes it according to the
image_max_size
value, then it loops through each pixel and gets the closest color to the pixel color, among those saved in the dict fromstep 4
, and save those color in a list
- CREATE MOSAIC
it gets, from the folder of frames, the frames corresponding to the colours saved in the list from
step 4
, and places those frames in a new big image
The only purpose of this example is to make you note how the result may vary depending on the dominant colours of the video, as probably, using this kind of super-colourful images is not the best thing to do with this program.
In fact, you can see that the logo mosaic at the top of this file is so similar to the original image that the difference between the colours is irrelevant.
Now the example.
INPUT IMAGE
CODE 1
import mozaiku
mozaiku.from_youtube(
'https://www.youtube.com/watch?v=iCnbgXyU09c',
'colours.jpg',
'colours_mosaic_1.jpg',
image_max_size = 200,
frames_size = 200
)
Assuming the frames are bigger than
200x200
, the output mosaic will have the biggest side equal toimage_max_size * frames_size
, in this example40000
.
So here the output image is40000x24000
NOTE: I can't show the real image cause it's too big for GitHub, these are resized.
OUTPUT IMAGE 1
CODE 2
import mozaiku
mozaiku.from_youtube(
'https://www.youtube.com/watch?v=OMa9bTd2qi0',
'colours.jpg',
'colours_mosaic_2.jpg',
200,
200
)
OUTPUT IMAGE 2
I add inside []
two values between 0
and 5
.
The first is how much I think the task is difficul, whereas the second is the level of priority of the task.
This is also to help those who wants to contribute choose what to do.
- Additional Tools
-
[4.0, 3.5]
Mozaiku CLI -
[2.5, 0.5]
Mozaiku Telegram Bot
-
- Tests
- Improvements
-
[2.5, 4.5]
Improve program efficiency using threads or asynchronous functions
-
If you want to test this program on other operating systems or with other versions of Python, you have to make sure every function works, is able to print log and progress barand is able to delete temporary files.
Currently tested on:
- Windows 10 Home 20H2
- Python Versions Tested
3.7.10
3.8.6
- Python Versions Tested
If you want to contribute to this project I’d recommend having a look at open issues if there are any, or at the checklist.
Otherwise any kind of improvement or suggestion is welcome, from improving an entire algorithm to correcting even a typo, improving comprehensibility of function docs or this README file.
The idea of a video to mosaic project is completely mine* and so is also the main algorithm, however I had to look up some stuff, like how to split a video into frames, how to get the closest color and how to merge images.
Thanks to all of you random guys who faced these problems before me.
* I didn’t know whether a similar thing already existed or not, and I created it without looking at similar projects and without anyone asking for it