GithubHelp home page GithubHelp logo

github-naresh / manipulator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jorgt/manipulator

0.0 1.0 0.0 861 KB

Turn images into paint-by-numbers! [kmeans, edge detection, flood fills]

JavaScript 98.06% HTML 1.94%

manipulator's Introduction

Simple image manipulator

Make your own coloring book or paint by numbers kit. This is very much a work in progress.

This library can bring an image down to k number of median colors using k-means, and can then use an automaton based smoothing or a region-based smoothing to bring down the number of cells in the image to simplify more. Uses edge detection to show just the outlines of all regions.

Uses a promise to make all steps more transparant.

Especially on larger images, this is not going to be fast. Look at the console to see progress.

Technical issues:

  • edge detection needs a bit of work. There seem to be occasional cells out of bounds.
  • determine the center of a cell
  • automaton smoothing, add cells pixels being 'born' also.
  • optimize cell merging. cells should merge with either the largest neighbor or the neighbor closest in color. Haven't worked out yet how to determine neighboring cells.
  • Once everything is working, I might check run time.

Missing features:

  • ability to display colors used
  • ability to mark a cell with the number of the color used

Example:

var manipulator = Manipulator('house.jpg');

manipulator.then(function(image) {
    //display the working canvas in the dom
    //nice to see what's happening
    image.append();
    return image;
}).then(function(image) {
    //brings an image down to - in this case - 5 colors
    image.kmeans(5);
    return image;
}).then(function(image) {
    //automaton-based smoothing. one pass only, 
    //automatically converts a pixel to the color
    //of it's most numerous neighbor
    image.smoothing(1, 0);
    return image;
}).then(function(image) {
    //3 passes that merge all cells under 70 pixels
    image.mergeCells(3, 70)
    return image;
}).then(function(image) {
    //another cell merge, 2 passes to merge all cells under 100 px
    image.mergeCells(2, 100)
    return image;
}).then(function(image) {
    //display all edges, in black
    image.edges(false, [0,0,0])
    return image;
}).done(function(image) {
    //discard the canvas and display a png instead.
    image.convert();
    console.log('... the end')
})

Outcomes

note: Because k-means adds some randomness, and because the screenshots below are taken from different runs, they differ slightly in shapes and colors (beyond the effect demonstrated).

The original.

Original

Brought back to 10 median colors

median

Smoothed over once, this creates a layered effect

smoothed

Small cells are removed from the image and merged into larger ones

median

Display borders

median

Display borders only

median

manipulator's People

Contributors

jorgt avatar

Watchers

 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.