Giter Site home page Giter Site logo

image-processing's Introduction

This is a scratch pad for a JavaScript library (written in CoffeeScript) for processing images. Adjustments are applied to <img> tags by replacing the image with a <canvas>.

Example:

Assuming your markup contains <img id="image" src="boat.png"> you could do something like this:

image = new img.Image( document.getElementById('image') );
image.setSaturation(.5);
image.draw()

Creating actions

Create a custom action by subclassing img.actions.Action and overriding either the adjustPixel or apply methods.

Adjusting a single pixel

Overwrite adjustPixel if your algorithm simply applies a calculation to a single pixel (for example, greyscale):

class Greyscale extends img.actions.Action

  # Parameters: the red, green, blue, and alpha values of the source pixel.
  # Returns: the new (adjusted) values for the pixel.
  applyToPixel: (r, g, b, a) ->
    v = r*0.3 + g*0.59 + b*0.11
    [v, v, v, 255]

Complex actions

If your action cannot be applied per-pixel (for example, the new value for a pixel depends on the values of its neighbouring pixels) you can override the apply method to process the image data however you want:

class Mosaic extends img.actions.Action

  # Parameter: the ImageData of the source image (array of pixel values).
  # Returns: the new (adjusted) array of pixel values.
  apply: (imageData) =>
    # Your crazy processing goes here...
    return imageData

The code is mostly experimental, but you might find some useful utilities hidden inside. Feel free to fork & add new stuff, or to repurpose however you see fit.

image-processing's People

Contributors

kylefox avatar

Stargazers

 avatar

Watchers

 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.