Giter VIP home page Giter VIP logo

python-photo-mosaic's Introduction

mosaic

This utility can be used to generate photo-mosaic images. There are several mosaic libraries.

There is no cheating with semi-transparent overlays, tile tinting, or repeating images (by default).

This one is focused on maximum accuracy (using scikit's Mean Squared Error). This is a pixel by pixel comparison to produce a best match. Other libraries simplify this by only comparing against a limited (averaged, antialiased) number of pixel from the original sector, or just compare against the histograms. Producing large, highly detailed mosaics takes much time!

As well as an image to use for the photo-mosaic (most common image formats are supported), you will need a large collection of different images to be used as tiles. The tile images can be any shape or size (the utility will automatically crop and resize them) but for good results you will need a lot of them - a few hundred at least. One convenient way of generating large numbers of tile images is to extract screenshots from video files using ffmpeg.

Prerequisites

pip install scikit-image numpy pillow

Usage

create_mosaic(
    subject="/path/to/source/image", 
    target="/path/to/output/image", 
    tile_paths=["/path/to/tile_1" , ... "/path/to/tile_n"],
    tile_ratio=1920/800, # Crop tiles to be height/width ratio
    tile_width=300, # Tile will be scaled
    enlargement=20, # Mosiac will be this times larger than original
    reuse=False, # Should tiles be used multiple times?
    color_mode='L',  # RGB (color) L (greyscale)
) 

Sample: Sean Connery made of screenshots from his Bond films

Sean starred in 7 Bond films. A still every 3 seconds yields about 10,000 images. 2,500 unique stills are matched and used below: Sample

Image Aspect Crop with Focus (Bonus Feature)

Ability crop an image to the desired perspective at the maximum size available. Centerpoint can be provided to focus the crop to one side or another.

For example, if we are cropping the left and right sides and the left side is more interesting than the right side:

from PIL import Image
img = aspect_crop_to_extent(
        img=Image.open("/path/to/image"), 
        target_aspect=1, # width / float(height) -- 1 is square
        centerpoint=(0,0), # (width, height) -- we will focus on the left, and crop from the right
)

Changed from original project (https://github.com/codebox/mosaic):

  • ability to not reuse tiles
  • increased quality of match by comparing against whole tile images
  • increased quality of mosaic by starting with the center instead of top left
  • ability to input color mode

Tested with:

  • Python 3.6.5
  • numpy==1.14.4
  • Pillow==5.1.0
  • scikit-image==0.14.1

python-photo-mosaic's People

Contributors

dvdtho avatar codebox avatar

Stargazers

Giovanni Boscan avatar Giacinto Carlucci avatar Wasabi Ice Cream avatar Matt Newell avatar  avatar Naveen Rawat avatar Supersonic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.