Code Monkey home page Code Monkey logo

mahalanobis's Introduction

mahalanobis

Image pattern recognition with Mahalanobis & Euclidean distances

Authors

Luiz Eduardo Pizzinatto

&

Bruno Martins Crocomo

Execution

python Main.py

Usage

  • Load an image
  • Select (in that image square) a small pattern color to recognize (change radius for thicker/larger lines)
  • Define any threshold (between 0 and 255)
  • Choose any distance as Mahalanobis or Euclidean
  • Press test
  • Check average color value, play with threshold and re-test to check new results

Examples

Two tests bellow, selecting some forehead pixels as pattern. As you can see, Mahalanobis distance is more accurate to detect the same pattern. forehead test for euclidean distance forehead test for mahalanobis distance

Two tests bellow, selecting some black tshirt pixels. Again, Mahalanobis distance is more accurate than Euclidean distance. tshirt test for euclidean distance tshirt test for mahalanobis distance

Infos

Mahalanobis distance

From the small pattern selected (a couple of pixels), the covariance inverse matrix is calculated from each pixel RED, GREEN and BLUE components. Hence, Mahalanobis distance is made as follows:

	distance = (x-y) * A^(-1) * (x-y)T

where:

    x is the element we want to discover the distance (with its own RED, GREEN, BLUE values)
    y is the average basis element, (i.e. an element with average RED, GREEN, BLUE value  from all selected patterns)
    A^(-1) is the covariance inverse matrix from the selected patterns

This distance was normalized as:

	norm = exp(-distance) * 255

The multiplication by 255 was made to generate a gray scale.

As small distances generate large normalized values and when RGB components become more white when near to 255, then distance is used as -distance. The value was inverted so that samples with small distances become darker and larger distances become whiter.

Euclidean distance

This was made as being the distance between each pixel from original image in relation to average center of patterns, without windowing.

mahalanobis's People

Contributors

pizzinatto22 avatar

Stargazers

 avatar 宗艺墨 avatar Lorenzo Borelli avatar Vilmar Adriano Bussolaro avatar Gaurav avatar

Watchers

James Cloos avatar Bruno Martins Crocomo 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.