Giter Site home page Giter Site logo

image-js / image-js Goto Github PK

View Code? Open in Web Editor NEW
648.0 26.0 64.0 46.48 MB

Image processing and manipulation in JavaScript

Home Page: https://image-js.github.io/image-js

License: MIT License

JavaScript 99.24% HTML 0.76%
image image-analysis image-processing nodejs javascript convolution roi hacktoberfest

image-js's Introduction

image-js

Advanced image processing and manipulation in JavaScript.

image-js is a full-featured library that can deal with simple image processing (color leveling, grey image, mask, resize, rotation, etc.) as well as advanced processing on scientific images (Region of interest (ROI), Hull curve, minimal boundary rectangle (MBR), particle size and orientation, cell imaging, etc.).

Zakodium logo

Maintained by Zakodium

NPM version build status Test coverage npm download

Installation

$ npm install image-js

Features

Supported image formats

The following formats can be loaded by image-js:

  • PNG (8 or 16 bits, color or greyscale, with or without alpha, palette 1 - 8 bits)
  • JPEG
  • TIFF (8 or 16 bits, color or greyscale, supports LZW compression)

The following formats can be saved by image-js:

  • PNG (8 or 16 bits)
  • JPEG
  • BMP (black and white)

Native support for various bit depths and image kinds

image-js was developed to be used in scientific applications where we often have to work on images that have more that 8 bits per channel.
Unlike many other libraries, if a 16-bit greyscale PNG is decoded, the resulting image has only one 16-bit channel and no pixel information is lost.

image-js can work with images that have 1 (binary), 8, 16 or 32 bits per channel.
It can accept an arbitrary amount of color channels (usually 1 or 3) and can handle an additional alpha component.

Basic image manipulation

image-js can be used to do simple image manipulations such as:

  • Resize
  • Crop
  • Rotate
  • Convert to greyscale
  • Invert colors
  • Gaussian blur
  • Extract individual channels (red, green or blue)
  • And more...

Statistics

image-js implements a number of functions to get statistics about an image:

  • Histogram
  • Max, min, median value
  • And more ...

Advanced features for computer vision

  • Image thresholding (otsu, triangle, ...)
  • Regions of interest
  • Convolution with custom kernel
  • Sobel filter
  • Morphological transformations (open, close, erode, ...)

An example using npm and node

Install the library:

npm i image-js

An example of code manipulating the image 'cat.jpg' (you need to create it).

const { Image } = require('image-js');

execute().catch(console.error);

async function execute() {
  let image = await Image.load('cat.jpg');
  let grey = image
    .grey() // convert the image to greyscale.
    .resize({ width: 200 }) // resize the image, forcing a width of 200 pixels. The height is computed automatically to preserve the aspect ratio.
    .rotate(30); // rotate the image clockwise by 30 degrees.
  return grey.save('cat.png');
}
node index.js

A greyscale image will be saved in the same folder.

Examples in the browser

Load an image and convert it to grey

<html>
  <head>
    <script src="https://www.lactame.com/lib/image-js/0.21.2/image.min.js"></script>
  </head>

  <body>
    <img
      id="color"
      src="https://www.lactame.com/github/image-js/image-js/3073b80c7d626196cb669f9d617f491a8338ca66/test/img/taxi/original.jpeg"
    />
    <img id="result" />

    <script>
      async function process() {
        let image = await IJS.Image.load(document.getElementById('color').src);

        let grey = image.grey();

        document.getElementById('result').src = grey.toDataURL();
      }
      process();
    </script>
  </body>
</html>

Try it

Create a mask

Try it

Paint a mask

Try it

Filter a mask using Region Of Interests (ROIs)

Image-js has a powerful Region of Interests Manager that allows to create ROIs from different sources. The ROIs can then be filtered, manipulated and finally painted to an RGBA image.

Try it

When extracting a mask from a ROI you have many options (contour, box, filled, center, hull or normal). Here it looks better to use the filled ROI.

Try it

Advanced analysis of SEM / TEM images

This library is able to deal with complex analysis involving images of cell or SEM / TEM. It will deal correctly with 16 bits grey scale images (TIFF or PNG) commonly found in scientific results.

In this example we will annotate an SEM / TEM image by coloring each particle and show the surface of them.

We also display a table containing a summary of all the identified particles.

Try it

Development

Contributions to code or documentation are welcome! Here are a few tips on how to setup a development environment for image-js.

Canvas

The canvas native addon library is required for all tests to pass. You can follow the instructions to install it on your OS here.

License

MIT

image-js's People

Contributors

adam-coster avatar andcastillo avatar bo-carey avatar cheminfo-bot avatar cherewaty avatar eh-dub avatar fa-b avatar fabian0007 avatar gianluca-moro avatar gnodar01 avatar greenkeeper[bot] avatar greenkeeperio-bot avatar incanus avatar jajoe avatar jonathanwbn avatar juldenereaz avatar juninholiveira avatar kellyjoha avatar kjappelbaum avatar klowner avatar lonelyevil avatar lpatiny avatar maasencioh avatar matthewjosephtaylor avatar miaulightouch avatar nayangupta824 avatar sebastien-ahkrin avatar stropitek avatar targos avatar yaceee 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image-js's Issues

color512 -> color

Transform a RGBA image by keeping only the 3 higher bits of each color.

  • 2^5 = 8
  • 8^3 = 512

There should be a way so that after applying this filter, getting a histogram yields the correct 512 slots

computers are getters

and add a property in a "computed" object.
all in-place modifications clear this object

Main goal

copied from README:

We would need a image library allowing to automatically a set of images on the internet.

This could include count of ROI, shape of ROI, relation between ROI

Get inspired:

Webworkers:

Images should be stored as a Uint8ClampedArray containing the underlying pixel representation of the image. If no such array is given, an image with a black rectangle of the given dimension will be created.
https://developer.mozilla.org/en-US/docs/Web/API/ImageData/ImageData

New filter : color(nbColor, options)

Create a filter that allows to reduce the number of color of the image to the specified number

Many algorithm could be implemented

There should be a way to know the rgb of the colors.

The histogram should also take into account the selected colors

Refactor completely ROIs

The idea is that from an IJ object we have getROIManager(options)

This will create a new object

ROIManager

From ROIManager we can

  • putMask(mask, label, options): this will create
  • select(label, options): by default label is "default"
  • paintImage(label, options):
  • resetPaintedImage: get back a copy of the original image in RGBA
  • getPaintedImage

Binary mask and array of int8 ?

Should we store binary mask by playing with bits in a int8 ?

We should make a test case ... on jsperf ... but it is currently broken !

Implement "mask"

The mask should allow to filter based on a matrix of values.
This matrix should had a odd number of columns / rows and would generate an error otherwise.
After applying the mask the results are "normalised" so that the sum or the points of the matrix applied is one. This value is of course constant except for the corners and borders (depending the size of the matrix). Need to think how this could be fully optimised.

https://courses.cs.washington.edu/courses/cse576/book/ch3.pdf

top left position

An image may have a top / left optional coordinates.

This will be useful when creating region of interests (ROI) and could also give the possibility to combine backs region or superimpose region on the original image.

Those coordinates would be taken into account when doing operation on a set of images.

Mask and parameters

The "intensity" mask was not well implemented because:

  • it should be in the folder mask and a separate mask algorithm
  • the parameter "intensity", algorithm and useAlpha should be taken into accound

new Image() and kind problem

kind is just a String that allow to preset default options.
They will be overridden by values from the options object.

Package name for npm

We need to find a name to publish the package on npm.

It is not directly possible to use ij, as another "project" is squatting the name (this is not allowed, we could ask the npm team to delete it).

Anyway, IMHO ij is probably not the best name. Yes, it is short, but it's not easy to pronounce and it's not obvious what it means.

I think that whatever the name is, it should have the full "image" word in it.
So with that in mind, if we look in npm there are already:

image-js is still available. It is a bit redundant to add js because npm packages are by definition written in JavaScript, but unless we find something else, it is a good option that reflects the name of the organisation and the domain name(s).

Properties versus functions

In javascript it is easy to attach a function to a property. This means that the property is calculated (and the function executed) only if we need to get it's value.
This is done using the getter / setter functions.

We use this for example to get the histogram for an image. The problem with this approach is that you can not have options.
So in the case of histogram we have a corresponding function getHistogram(options) is we want more flexibility.

I think we should stay coherent in the whole code and systematically a short name for the property with default options and a get or to or ???

So it would be :

  • img.grey
  • img.toGrey(options)

Boolean operation on images and more ...

Would be nice to be able to combine images using:

  • or
  • not
  • and
  • ...

This means we should be able to find the smallest common format between the 2 pictures.

One application could be to paint the area of interests

histogram

Returns an histogram of the points present in the picture
Options:

  • alpha (by default false), we don't return the array for the alpha channel
  • nbSlots, by default the number of colors allowed in the channel

Returns an array (if nbChannel + alpha == 1) or an array of array

Should work with all the formats, also with mask images

Implement many masks

ImageJ was developed in java and contains a lot of interesting code. The license is BSD meaning that we can if we cite them get strongly inspired by their code.

We would like to have all the masks that are implement in imageJ based on their code

https://github.com/imagej/imagej1/blob/master/ij/process/AutoThresholder.java

  • Default
  • Huang
  • Intermodes
  • IsoData
  • IJ_IsoData,
  • Li
  • MaxEntropy
  • Mean
  • MinError
  • Minimum
  • Moments
  • Otsu
  • Percentile
  • RenyiEntropy
  • Shanbhag
  • Triangle
  • Yen

Values obtained with ImageJ for grayscale_by_zimmyrose.png :
image

Allow function in the mask method

Allow as parameter a function that will select the points by returning true / false. Could be nice that a point can get neighbours

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.