Abraia Python SDK
Project description
Abraia-Multiple image analysis toolbox
The Abraia-Multiple package provides and easy and practical way to analyze and classify images directly from your browser. You just need to click on the open in Colab button to start with one of the available notebooks:
The multiple module provides support for HyperSpectral Image (HSI) analysis and classification.
MULTIPLE is result and it is being developed by ABRAIA in the Multiple project.
Configuration
Installed the package, you have to configure your ABRAIA KEY as environment variable:
export ABRAIA_KEY=api_key
On Windows you need to use set
instead of export
:
set ABRAIA_KEY=api_key
NOTE: To persist the configuration use your system options to set your ABRAIA_KEY environment variable and avoid to run the previous command every time you start a terminal/console session.
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 directly load and save images. You can easily load the image data and the file metadata, or save a new image.
from abraia import Abraia
abraia = Abraia()
img = abraia.load_image('test.jpg')
meta = abraia.load_metadata('test.jpg')
abraia.save_image('test.png', img)
You can directly visualize the image using Matplotlib.
from abraia.plot import plot_image
plot_image(img, 'Image')
Upload and list files
Upload a local src
file or a remote url
to the cloud path
and return the list of files
and folders
on the specified cloud folder
.
folder = 'test/'
src = 'images/test.png'
path = f"{folder}test.png"
abraia.upload_file(src, path)
files, folders = abraia.list_files(folder)
Automatic image detection
Simply detect labels (tags), capture text, or detect faces in images (must be in JPEG format).
labels = abraia.detect_labels(path)
lines = abraia.capture_text(path)
faces = abraia.detect_faces(path)
Download and remove files
You can download or remove an stored file just specifying its path
.
path = 'test/birds.jpg'
dest = 'images/birds.jpg'
abraia.download_file(path, dest)
abraia.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
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
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
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]
Convert images
The JPEG image format is still the most common format to publish photos on the web. However, converting images to WebP provides a significant improvement for web publishing.
To convert images to a web format (JPEG, PNG, WebP) or between these formats you just need to change the filename extension for the destination file:
abraia convert garlic.jpg garlic.webp
In addition, you can also convert SVG and PSD files. For instance, converting a SVG to PNG is so simple as to type the command bellow:
abraia convert bat.svg bat.png
The SVG vector image is rendered in a Chrome instance to provide maximum fidelity, and preserving the transparent background.
Moreover, you can easily convert a PSD file (the layered image file used in Adobe Photoshop for saving data) flattening all the visible layers with a command like bellow:
abraia convert strawberry.psd strawberry.jpg
abraia convert strawberry.psd strawberry.png
When the PSD file is converted to JPEG a white background is added automatically, because the JPEG format does not support transparency. Instead, using the PNG or the WebP format you can preserve the transparent background.
Or, convert a batch of Photoshop files with a simple command. Just copy your PSD files to a folder, for instance the photoshop
folder, and convert all the files in that folder.
abraia convert photoshop
You can also take web from the command line just specifying and url to get the capture.
abraia convert https://abraia.me screenshot.jpg
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
Built Distribution
File details
Details for the file abraia-0.9.1.tar.gz
.
File metadata
- Download URL: abraia-0.9.1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3cb4aa26b426e41660c958ad2dc5f0381fce4624f1ee05a8eba2b536c71b3f2 |
|
MD5 | 66810fbaf1e4b8185e5a17a0b04db22d |
|
BLAKE2b-256 | c281ed11cf355cd0c5f60c6be56dd743025e912e007af937466e6622b3aced4f |
File details
Details for the file abraia-0.9.1-py2.py3-none-any.whl
.
File metadata
- Download URL: abraia-0.9.1-py2.py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc181f512f5d986ac42e5cbbf1f58d5eae2d02612ea91bef876504cbf6a605f |
|
MD5 | 68a7c31bfd30e43b2a5904226adef44b |
|
BLAKE2b-256 | b3226cfc784a889e9552dd724d3d50af9439a8673ffb2104e712bf4c6a1cfb11 |