Skip to content

xtensor plugin to read and write images, audio files and numpy (compressed) npz

License

Notifications You must be signed in to change notification settings

Fromeworld/xtensor-io

 
 

Repository files navigation

xtensor-io

Travis ReadTheDocs Binder Join the Gitter Chat

Reading and writing image, sound and npz file formats to and from xtensor data structures.
Try it live in the browser!

Introduction

xtensor-io is an early developer preview, and is not suitable for general usage yet. Features and implementation are subject to change.

xtensor-io offers API of to read and write various file formats into xtensor data structures:

  • images,
  • audio files,
  • NumPy's compressed storage format (NPZ).

xtensor-io wraps the OpenImageIO, libsndfile and zlib libraries.

Installation

xtensor-io is a header-only library. We provide a package for the conda package manager.

conda install xtensor-io -c QuantStack -c conda-forge
  • xtensor-io depends on xtensor ^0.15.5.

  • OpenImageIO, libsndfile and zlib are optional dependencies to xtensor-io

    • OpenImageIO is required to read and write image files.
    • libsndfile is required to read and write sound files.
    • zlib is required to load NPZ files.

All three libraries are available for the conda package manager.

You can also install xtensor-io from source:

mkdir build
cd build
cmake ..
make
sudo make install

Usage

// loads png image into xarray with shape HEIGHT x WIDTH x CHANNELS
auto arr = xt::load_image("test.png");

// write xarray out to JPEG image
xt::dump_image("dumptest.jpg", arr + 5);

// load npz file containing multiple arrays
auto npy_map = xt::load_npz("test.npz");

auto arr_0 = npy_map["arr_0"].cast<double>();
auto arr_1 = npy_map["arr_1"].cast<unsigned long>();

// open a wav file
auto audio = xt::load_audio("files/xtensor.wav");
auto& arr = std::get<1>(audio); // audio contents (like scipy.io.wavfile results)

// save a sine wave sound
int freq = 2000;
int sampling_freq = 44100;
double duration = 1.0;

auto t = xt::arange(0.0, duration, 1.0 / sampling_freq);
auto y = xt::sin(2.0 * numeric_constants<double>::PI * freq * t);

xt::dump_audio("files/sine.wav", y, sampling_freq);

License

We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.

About

xtensor plugin to read and write images, audio files and numpy (compressed) npz

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jupyter Notebook 46.7%
  • C++ 36.4%
  • CMake 16.9%