HSKL: Hyperspectral-scikit-learn
Hyperspectral image analysis using scikit-learn
Installation
The package can be installed from pip:
pip install hskl
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:
Test image and ground truth labels:
Test image and predicted labels:
Notes:
- Shape of
trainandtestarrays are (DimX, DimY, SpectralChannels). - Shape of
labelandpredictionarrays are (DimX, DimY). - Labeling convention for classifiers:
(a) Datatype:
label.dtype == np.uint8. (b) Labeled classes start from integer 1. Pixels withlabel == 0are ignored (masked out). - Dimension(s) of
trainandlabelmust be consistent:train.shape[0] == label.shape[0]andtrain.shape[1] == label.shape[1]. - Inputs:
train,test, andlabelcan also be lists ofnp.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
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
Some functionalities in this package are provided by Spectral Python (SPy): https://github.com/spectralpython/spectral
Metadata
Release files for hskl 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hskl-0.0.2.tar.gz | 8.4 kB | Without provenance | Details for hskl-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hskl-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for hskl-0.0.2-py3-none-any.whl |
Total release size: 19.4 kB
Release files / hskl-0.0.2.tar.gz
| Download URL | hskl-0.0.2.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
725e32cfe2e3f9d23b3036333941fe4a63bc5eea5794a28e9434f8ae5166fdb6
|
|
BLAKE2b-256 checksum How to use checksums |
034c3b97e237bf83a3e5efbe1ffb433eaba9253d0d699b48e468410769184746
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
|
Release files / hskl-0.0.2-py3-none-any.whl
| Download URL | hskl-0.0.2-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7468af1d69dd2a6282d84914af9e8b2b5a030929108b91831ffd84a6d87fd66
|
|
BLAKE2b-256 checksum How to use checksums |
80f8ce7113c2d266e267148efffddec22553454c41f9d83fffbf4c96fc5be8ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
|
Security for hskl 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.