Giter Club home page Giter Club logo

glcmbin5's Introduction

Binned Cython 5 Feature GLCM

Notice

This project has mainly migrated to https://github.com/Eve-ning/glcm-cupy which has many more new features & optimization improvements.

This repository will be left here for archival purposes.

Result

Photo by Flo Maderebner from Pexels

400 Times faster, the above image takes 6+ Days to process, compared to 24 Minutes with glcmbin5 with bins=16. YMMV

Installation

I recommend to install this via forking. The pip version may be unstable.

Run this command with the c_setup.py here

python c_setup.py build_ext --inplace

Main Features

  • Implemented in Cython, means you get C-Lang Speed on Python
  • 2/4/6/8-directional GLCM, in the case where orientation doesn't matter
  • Memory Optimized, calculations are per window, thus a large intermediate GLCM isn't used, saving GBs of memory.

Pitfalls

This doesn't work with parallel processing for some reason, I couldn't get it to work unfortunately.

If you derived this work to make it parallel, please let me know! I would love to use it.

Speed

This is ~400 times faster than using skimage.feature.graycomatrix and graycoprops because this is Cython optimized, YMMV.

With a 2000x1000x3 image, it takes around 6+ minutes. Compared to 39 hours with skimage

GLCM Progress: 100%|██████████| 12/12 [06:49<00:00, 34.09s/it]

Memory Size

Binning the input array reduces size of GLCM, also increases performance. Though there's no substantial evidence of it improving nor deproving results.

With this algorithm, I omit generating the whole GLCM, instead, it's integrated in the GLCM feature calculation. Memory used is freed asap.

Example

You can also see an example in /examples

from glcm.glcm import CyGLCM
import numpy as np
ar = ...
glcm = CyGLCM(ar.astype(np.float32),
              radius=3,
              bins=8,
              pairs=('H', 'V', 'SE', 'NE')
              ).create_glcm()

Arguments

  • radius: The radius of the GLCM window
  • bins: The number of bins to use
  • pairs:
    • H: Horizontal Pair
    • V: Vertical Pair
    • SE: South-East Diagonal Pair
    • NE: North-East Diagonal Pair

I/O

Input:

  • ndim = 3
  • shape=(in_dim0, in_dim1, channel)

Output:

  • ndim = 4
  • shape=(in_dim0, in_dim1, channel, features)
  • Methods:
    • Homogeneity
    • Correlation
    • Angular Second Moment
    • GLCM Mean
    • GLCM Variance

Progress Bar

The progress bar value is the current pair calculated.

Gotchas

GLCM Shrink

The resulting GLCM array will be smaller than the original.

GLCM Dimension = Dimension - (2 * radius + step_size) = Dimension - Diameter

Data Type float32

Arrays MUST BE in np.float32, you need to cast it.

ar.astype(np.float32)

Features

Based on GLCM Texture: A Tutorial v. 3.0 March 2017.

For an effective segmentation, we just need 5 features as selected here.

Many features are not significantly orthogonal, hence more will introduce redundancy.

Chosen methods are for simplicity and efficiency in coding.

0.1.5 swapped Contrast for Homogeneity as it may be more orthogonal.

Binning

Arrays are Binned before going through GLCM.

All arrays will be processed to integer values [0,bin-1] band-independently.

Citation

If you have used or referenced any of the code in the repository, please kindly cite

@misc{glcmbin5,
  author = {John Chang},
  title = {Binned Cython 5 Feature GLCM},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub Repository},
  howpublished = {\url{https://github.com/Eve-ning/glcmbin5}},
}

Acknowledgements

glcmbin5's People

Contributors

eve-ning avatar

Stargazers

 avatar

Watchers

 avatar  avatar

glcmbin5's Issues

Single band images?

This seems really cool, but it seems to be restricted to 3 band (RGB) images. Is it possible to apply it to single band (greyscale) images?

I can force it by duplicating the band three times, but not super elegant.

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.