otsu

0.0.5 • Public • Published

otsu

Otsu's Method is way of implementing automatic thresholding. It is a binarization algorithm which can be used to select the optimal threshold between foreground and background quantities based on finding the minimum point of cross variance. This is particularly useful when performing segmentation in image processing.

code style: prettier

You can find an awesome description of the algorithm, which inspired this repository, here.

🚀 Getting Started

Using npm:

npm install --save otsu

Using yarn:

yarn add otsu

✍️ Usage

It's really simple to find the threshold of your image. All you have to do is supply the data!

In the example below, we have a one-dimensional array of intensity data. Most greyscale image formats, such as MNIST, can be fed directly into otsu this way. However, images that consist of multiple attributes per pixel (such as (r,g,b)) will first require pre-processing.

import otsu from 'otsu';
 
const intensity = [255, 0, 128, 4, 95 ...];
const t = otsu(intensity);
 
console.log(t); // i.e. 128
 
const thresholded = intensity.map(e => (> t ? 1 : 0));

✌️ License

MIT

Buy @cawfree a coffee

Package Sidebar

Install

npm i otsu

Weekly Downloads

208

Version

0.0.5

License

MIT

Unpacked Size

13.2 kB

Total Files

11

Last publish

Collaborators

  • cawfree