Skip to main content

Abraia Python SDK

Project description

Build Status Python Package Package Downloads

Abraia-Multiple image analysis toolbox

The Abraia-Multiple image analysis toolbox provides and easy and practical way to analyze and classify multispectral and hyperspectral images directly from your browser. You just need to click on the open in Colab button to start with one of the available Abraia-Multiple notebooks:

  • Hyperspectral image analysis

  • Hyperspectral image classification

The Abraia-Multiple SDK has being developed by ABRAIA in the Multiple project to extend the Abraia Cloud Platform providing support for straightforward HyperSpectral Image (HSI) analysis and classification.

classification

Configuration

Installed the package, you have to configure your Id and Key as environment variables:

export ABRAIA_ID=user_id
export ABRAIA_KEY=user_key

On Windows you need to use set instead of export:

set ABRAIA_ID=user_id
set ABRAIA_KEY=user_key

Hyperspectral image analysis toolbox

MULTIPLE provides seamless integration of multiple HyperSpectral Image (HSI) processing and analysis tools, integrating starte-of-the-art image manipulation libraries to provide ready to go scalable multispectral solutions.

For instance, you can directly load and save ENVI files, and their metadata.

from abraia import Multiple

multiple = Multiple()

img = multiple.load_image('test.hdr')
meta = multiple.load_metadata('test.hdr')
multiple.save_image('test.hdr', img, metadata=meta)

Upload and load HSI data

To start with, we may upload some data directly using the graphical interface, or using the multiple api:

multiple.upload_file('PaviaU.mat')

Now, we can load the hyperspectral image data (HSI cube) directly from the cloud:

img = multiple.load_image('PaviaU.mat')

Basic HSI visualization

Hyperspectral images cannot be directly visualized, so we can get some random bands from our HSI cube, and visualize these bands as like any other monochannel image.

from abraia import hsi

imgs, indexes = hsi.random(img)
hsi.plot_images(imgs, cmap='jet')

Pseudocolor visualization

A common operation with spectral images is to reduce the dimensionality, applying principal components analysis (PCA). We can get the first three principal components into a three bands pseudoimage, and visualize this pseudoimage.

pc_img = hsi.principal_components(img)
hsi.plot_image(pc_img, 'Principal components')

Classification model

Two classification models are directly available for automatic identification on hysperspectral images. One is based on support vector machines ('svm') while the other is based on deep image classification ('hsn'). Both models are available under a simple interface like bellow:

n_bands, n_classes = 30, 17
model = hsi.create_model('hsn', (25, 25, n_bands), n_classes)
model.train(X, y, train_ratio=0.3, epochs=5)
y_pred = model.predict(X)

Image analysis toolbox

Abraia provides a direct interface to load and save images as numpy arrays. You can easily load the image data and the file metadata, show the image, or save the image data as a new one.

from abraia import Multiple
from abraia.plot import plot_image

multiple = Multiple()

img = multiple.load_image('usain.jpg')
multiple.save_image('usain.png', img)

plot_image(img, 'Image')

plot image

Read the image metadata and save it as a JSON file.

import json

metadata = multiple.load_metadata('usain.jpg')
multiple.save_file('usain.json', json.dumps(metadata))
{'FileType': 'JPEG',
'MIMEType': 'image/jpeg',
'JFIFVersion': 1.01,
'ResolutionUnit': 'None',
'XResolution': 1,
'YResolution': 1,
'Comment': 'CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 80\n',
'ImageWidth': 640,
'ImageHeight': 426,
'EncodingProcess': 'Baseline DCT, Huffman coding',
'BitsPerSample': 8,
'ColorComponents': 3,
'YCbCrSubSampling': 'YCbCr4:2:0 (2 2)',
'ImageSize': '640x426',
 'Megapixels': 0.273}

Upload and list files

Upload a local src file to the cloud path and return the list of files and folders on the specified cloud folder.

import pandas as pd

folder = 'test/'
multiple.upload_file('images/usain-bolt.jpeg', folder)
files, folders = multiple.list_files(folder)

pd.DataFrame(files)

files

To list the root folder just omit the folder value.

Download and remove files

You can download or remove an stored file just specifying its path.

path = 'test/birds.jpg'
dest = 'images/birds.jpg'
multiple.download_file(path, dest)
multiple.remove_file(path)

Command line interface

The Abraia CLI tool provides a simple way to bulk resize, convert, and optimize your images and photos for web. Enabling the conversion from different input formats to get images in the right formats to be used in the web - JPEG, WebP, or PNG -. Moreover, it supports a number of transformations that can be applied to image batches. So you can easily convert your images to be directly published on the web.

Installation

The Abraia CLI is a Python tool which can be installed on Windows, Mac, and Linux:

python -m pip install -U abraia

The first time you run Abraia CLI you need to configure your API key, just write the command bellow and paste your key.

abraia configure

Resize images

To compress an image you just need to specify the input and output paths for the image:

abraia convert images/birds.jpg images/birds_o.jpg

Image compressed from url

To resize and optimize and image maintaining the aspect ratio is enough to specify the width or the height of the new image:

abraia convert --width 500 images/usain-bolt.jpeg images/usaint-bolt_500.jpeg

Usain Bolt resized

You can also automatically change the aspect ratio specifying both width and height parameters and setting the resize mode (pad, crop, thumb):

abraia convert --width 333 --height 333 --mode pad images/lion.jpg images/lion_333x333.jpg
abraia convert --width 333 --height 333 images/lion.jpg images/lion_333x333.jpg

Image lion smart cropped Image lion smart cropped

So, you can automatically resize all the images in a specific folder preserving the aspect ration of each image just specifying the target width or height:

abraia convert --width 300 [path] [dest]

Or, automatically pad or crop all the images contained in the folder specifying both width and height:

abraia convert --width 300 --height 300 --mode crop [path] [dest]

License

This software is licensed under the MIT License. View the license.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abraia-0.11.7.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

abraia-0.11.7-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file abraia-0.11.7.tar.gz.

File metadata

  • Download URL: abraia-0.11.7.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for abraia-0.11.7.tar.gz
Algorithm Hash digest
SHA256 b401758195149aff36709d983dbd50729db5b9c4ee1d0a53589cb9cbdf5bb2e7
MD5 523980c1c916986f8c03aee8fec339b6
BLAKE2b-256 2666f14670837cdbba7c838a827301688626c014344628b3c49a800076d32baf

See more details on using hashes here.

File details

Details for the file abraia-0.11.7-py3-none-any.whl.

File metadata

  • Download URL: abraia-0.11.7-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for abraia-0.11.7-py3-none-any.whl
Algorithm Hash digest
SHA256 86376e294241e9bbc7f61a262c03190d261b4524cf6ed1c5b4c9af1e3dfad974
MD5 374fadf07eca97d6df7348ce2f0f5860
BLAKE2b-256 226698a1c64b2fbce109c38ae1d2c28de1a900125bf7d5ece25c7d19b06bea42

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page