Git Product home page Git Product logo

otsu's Introduction

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 => (e > t ? 1 : 0));

✌️ License

MIT

Buy @cawfree a coffee

otsu's People

Contributors

cawfree avatar dependabot[bot] avatar jeremydouglass avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

nabikaz

otsu's Issues

TypeError: otsu is not a function

Sample Code:

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

package.json

{
  "dependencies": {
    "otsu": "^0.0.5"
  },
  "type": "module"
}

Error:

PS C:\Nabi\otsu> node .\test.js
file:///C:/Nabi/otsu/test.js:3
const t = otsu(intensity);
          ^

TypeError: otsu is not a function
    at file:///C:/Nabi/otsu/test.js:3:11
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

Node.js v19.7.0

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.