Giter Site home page Giter Site logo

qiancao / hskl Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 3.0 592 KB

A library for hyperspectral image analysis using scikit-learn.

Home Page: https://github.com/qiancao/hskl

License: BSD 3-Clause "New" or "Revised" License

Python 99.78% Shell 0.22%
hyperspectral image-analysis-toolbox machine-learning scikit-learn

hskl's Introduction

HSKL: Hyperspectral-scikit-learn

Hyperspectral image analysis using scikit-learn

Installation

The package can be installed using pip:

pip install hskl

Or install HSKL directly from the repository:

  1. Verify that git is installed:

    git --version

  2. Install HSKL:

    pip install git+https://github.com/qiancao/hskl.git

Usage

Training a pixel-level classifier for segmentation:

import os

from hskl.demo import dl_hyrank, load_hyrank
import hskl.classification as classification
import hskl.utils as utils

# Download, unpack, and load HyRANK dataset from current directory.
path = os.getcwd()
if not os.path.exists("HyRANK_satellite"):
    dl_hyrank(path)    
images, labels, _ = load_hyrank(path)

# Dimensional reduction using PCA, retain 99.9% image variance
pca = utils.pca_fit(images[0])
train, _ = utils.pca_apply(images[0], pca, 0.999)
test, _ = utils.pca_apply(images[1], pca, 0.999)
label = labels[0]
test_mask = labels[1]>0

# Train a classifier and predict test image labels
cl = classification.HyperspectralClassifier(
         method_name="LinearDiscriminantAnalysis")
cl.fit(train, label)
prediction = cl.predict(test)

# Visualization of training data, test prediction, and test ground truth
fig_objs_train = utils.overlay(train,label)
utils.save_overlay(fig_objs_train, "hyrank_train.png")

fig_objs_predict = utils.overlay(test,prediction*test_mask)
utils.save_overlay(fig_objs_predict, "hyrank_predict.png")

fig_objs_test = utils.overlay(test,labels[1])
utils.save_overlay(fig_objs_test, "hyrank_test.png")

Output:

Training image and ground truth labels:

Training

Test image and ground truth labels:

Testing Ground Truth

Test image and predicted labels:

Testing Prediction

Notes:

  1. Shape of train and test arrays are (DimX, DimY, SpectralChannels).
  2. Shape of label and prediction arrays are (DimX, DimY).
  3. Labeling convention for classifiers: (a) Datatype: label.dtype == np.uint8. (b) Labeled classes start from integer 1. Pixels with label == 0 are ignored (masked out).
  4. Dimension(s) of train and label must be consistent: train.shape[0] == label.shape[0] and train.shape[1] == label.shape[1].
  5. Inputs: train, test, and label can also be lists of np.ndarrays with each element satisfying the preceeding requirements.

Planned Features

In the near-term:

  • Test scripts and data
  • Grid search cross validation

In the long-term, support for:

  • Pipelines
  • Patch-based featurizer
  • Dask-enabled parallelism
  • Deep learning (PyTorch) models

Cite this Project

Qian Cao, Deependra Mishra, John Wang, Steven Wang, Helena Hurbon and Mikhail Berezin. HSKL: A Machine Learning Framework For Hyperspectral Image Analysis. Proc. IEEE WHISPERS. IEEE, 2021.

References

Karantzalos, Konstantinos, Karakizi, Christina, Kandylakis, Zacharias, & Antoniou, Georgia. (2018). HyRANK Hyperspectral Satellite Dataset I (Version v001). Zenodo. http://doi.org/10.5281/zenodo.1222202

Spectral Python (SPy): https://github.com/spectralpython/spectral

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.