Coder Social home page Coder Social logo

mosaic's Introduction

Mosaic

Mosaic makes it easy to create Photographic mosaics on still images or live video feeds.

MIT License Swift 5.1

Features

  • Fast: capable of processing live videos
  • Lightweight
  • Easy to use

Demo

Demo of real time mosaic generation. Captured at 60fps on an iPhone 8.

Usage

Quick Start

The following steps give you a quick way to get started with Mosaic. It's not meant to be used as is, since errors are not properly handled.

For a more in depth example, please refer to the Mosaic Sample App included in this repository.

  1. Get an array of UIImage instances. This is the image pool that will be used to populate the photo mosaic.
let images = [
    UIImage(named:"myImage_1.jpg")
    UIImage(named:"myImage_2.jpg")
    UIImage(named:"myImage_3.jpg")
    ...
]
  1. Initialize a Mosaic instance, passing in the UIImage instances created in the previous step.
let mosaic = try! Mosaic(imagePool: images)
  1. Finally, call the generate() function on the Mosaic instance previously created, and pass in the image (as a CGImage) that needs to be transformed into a photo mosaic.
let imageToTransform = UIImage(named:"myImage_4.jpg").cgImage!
let photoMosaic: UIImage = mosaic.generate(for: imageToTransform)

Pre Heat

There are a number of expensive tasks that need to be done before a photo mosaic can be generated for the first time.

For example, the average color of each image in the image pool needs to be computed exactly once.

This means that once a Mosaic instance is initialized, calling the generate() function for the first time will take longer than the subsequent calls.

To prevent this, Mosaic provides the preHeat() function. Use the preHeat() function when you know that there is a chance that a photo mosaic will be created in the future. This will ensure that the photo mosaic is created as fast as possible.

let mosaic = try! Mosaic(imagePool: images)
mosaic.preHeat()

Cheat Mode

It can be challenging to come up with enough images for the image pool. Indeed, for the photo mosaic to work well, the image pool needs a wide variety of images of different dominant colors.

Thankfully, Mosaic comes with a cheat mode! It is represented by an enum with the following values:

  • enabled: Mosaic will actively complete the image pool by generating new images close to the colors that are missing. It does so by adding an overlay on the image closest to the desired color. It will do so only for colors that are not already represented in the image pool.

If the image pool doesn't contain any image with a blue average color, enabling cheating will generate a new image with a blue overlay.

  • automatic (default): Mosaic will try to determine if it should cheat.
  • disabled: Mosaic will use the image pool as is. This is recommended when you have an image pool with a wide variety of dominant colors.

To use a specific cheat mode instead of the default one (automatic), simply pass a value when initializing a Mosaic instance.

Mosaic(imagePool: images, cheatDecision: .enabled)

How It Works

Mosaic takes an image to transform into a mosaic, as well as a pool of images. It recreates the image to transform using the pool of images.

License

See the License. You are free to make changes and use this in either personal or commercial projects. Attribution is not required, but highly appreciated. A little "Thanks!" (or something to that affect) is always welcome. If you use Mosaic in your one of your projects, please let us know!

mosaic's People

Contributors

boris-em avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.