What is it?A mosaic is defined as, a picture or decoration made of small, usually colored pieces of inlaid stone, glass. Python can be used to create mosaics, not from glass or tile but from your images and photographs. A single picture created from and consisting of other tiny images. It sounds like it should be complex but, Python makes it easy with only nine lines of code!
1. Installing the SoftwareInstallation is simple and requires a few Python Libraries. Before you get started make sure that your Raspberry Pi is up to date.
In the LX Terminal type: sudo apt-get update sudo apt-get upgrade then type: sudo apt-get install python-pip python-dev sudo pip install -U pip sudo apt-get install python-imaging sudo pip install Pymos 2. Python ProgramThe Python code for creating the mosaics is also very simple and basically asks you for the image you wish to make into a mosaic, the name of the outputted file and the folder where all the images are stored and then the size and fuzz of the final image. The real skill is in choosing the most appropriate size, zoom and fuzz to make the final image look professional and like a mosaic! Open a new Python window, use the code below:
from pymos.core import build_mosaic
build_mosaic( input_path="input_image_path.jpg", output_path="mosaic_output_path.png", collection_path="./path_to_folder_of_small_photos/", zoom=4, thumb_size=50, fuzz=20, new_colormap=False ) It really is this simple. Ensure that the program and the images files are stored in the same folder and then you are ready to create.
Ferran's awesome Mosic hack is here |
Creating a Mosaic3. Perfecting the LookTo create the perfect mosaic you will want to play around with the various settings in the code. The original quality of the images you are using and the colour variations required will all impact on the what the final image looks like. The first three elements set up which photo is the base of the mosaic, what the final image file will be called an also where the 'tile' images are stored.
The elements below can be altered and refined to make the final image look better. Using more tiles will make the image look better but each individual tile will lack detail.
|
- Home
- Python
- Ras Pi
-
Pi Hardware
- Pi-Hacks
-
Pi-Hacks 2
- The Joker
- Hologram Machine
- Google Vision: Camera Tell
- Yoda Tweets
- Pi Phone
- Darth Beats
- Twitter Keyword Finder
- Crimbo Lights Hack
- Xmas Elf
- Halloween 2016
- Halloween Hack 2015
- Socrative Zombie
- Voice Translation
- The Blue-Who Finder
- GPIO, Twitter
- Pi Chat Bot >
- PiGlow & Email
- Pibrella Alarm System
- SMS with Python >
- Pi-Hacks 3
- Minecraft
- Computing
- Contact Me
- Random Hacks