Selene is a C++17 image representation, processing and I/O library.
It currently contains, among other things
-
Statically and dynamically typed in-memory pixel and image data representations.
- Pixel<T, n>:
Statically typed multi-channel pixel value.
- For example,
Pixel<std:uint8_t, 3>
(shortcut:Pixel_8u3
) could represent an 8-bit RGB value, whilePixel<float, 1>
represents a single-channel floating point image.
- For example,
- Image<T>:
Statically typed class representing a 2-D image, owning its data.
- Example:
Image<Pixel_8u1> img_gray({320_px, 240_px}); // 8-bit grayscale image of size (320 x 240)
- Example:
- ImageView<T>:
Statically typed class representing a 2-D image view, i.e. pointing to non-owned memory.
Can be either mutable or constant.
- Example:
MutableImageView<Pixel<double, 10>> img(ptr, {width, height}); // view onto 10-channel floating point image data
- Example:
- DynImage:
Dynamically typed class representing a 2-D image.
- Its main use case is as an intermediate representation for decoded image data (from disk or memory) before
conversion to a strongly typed
Image<T>
.
- Its main use case is as an intermediate representation for decoded image data (from disk or memory) before
conversion to a strongly typed
- DynImageView: Dynamically typed class representing a 2-D image view. Can be either mutable or constant.
- Interoperability with OpenCV
cv::Mat
matrices: both wrapping (as view) or copying is supported, in both directions.
- Pixel<T, n>:
Statically typed multi-channel pixel value.
-
Functions for reading and writing image data in JPEG, PNG, and TIFF formats (from/to files or memory). The implementation cleanly wraps the libjpeg, libpng, and libtiff APIs.
- read_jpeg(), read_jpeg_header(), write_jpeg()
- read_png(), read_png_header(), write_png()
- read_tiff(), write_tiff()
- Convenience functions read_image()
and write_image(), being able to handle all formats.
- Example:
auto img_data = read_image(FileReader("image.png"));
- Example:
auto img_data = read_image(MemoryReader(data_ptr, size_bytes));
- Example:
-
Basic image processing functionality, such as:
- Image pixel access using
various interpolation algorithms
(nearest neighbor, bilinear) and
boundary handling strategies (no
check, replicate boundary, zero padding).
- Example:
const auto u = get<ImageInterpolationMode::Bilinear>(img, 8.5, 10.2);
- Example:
const auto v = get<BorderAccessMode::Replicated>(img, -5_idx, 10_idx);
- Example:
const auto w = get<ImageInterpolationMode::Bilinear, BorderAccessMode::ZeroPadding>(img, x, y)
- Example:
- Algorithms to apply point-wise
operations to images/views.
- Example:
for_each_pixel(img, [](auto& px){ px += 1; });
- Example:
const auto img_2 = transform_pixels(img, [const auto& px]{ return px + 1; });
- Example:
- Pixel-level and
image-level conversion
functions between different pixel formats (e.g. RGB -> Grayscale, etc.).
- Example:
const auto img_gray = convert_image<PixelFormat::RGB, PixelFormat::Y>(rgb_img);
- Example:
const auto img_bgra = convert_image<PixelFormat::RGB, PixelFormat::BGRA>(rgb_img, 255);
- Example:
- Transformations
such as transposing, flipping and rotating image data.
- Example:
const auto img_transposed = transpose(img);
- Example:
const auto img_flipped = flip<FlipDirection::Horizontal>(img);
- Example:
const auto img_rotated = rotate<RotationDirection::Clockwise90>(img);
- Example:
- Convolution operations using 1-D kernels
that can be applied in x- or y-direction on an image.
- Example:
const auto img_convolved = convolution_x<BorderAccessMode::Unchecked>(img, kernel);
- Example:
- Image pixel access using
various interpolation algorithms
(nearest neighbor, bilinear) and
boundary handling strategies (no
check, replicate boundary, zero padding).
-
Functions for binary IO from and to files or memory. The type of source/sink can be transparent to users of this functionality, via static polymorphism.
- FileReader / FileWriter: Reading/writing from and to files
- MemoryReader / MemoryWriter: Reading/writing from and to memory (raw pointer locations)
- VectorReader /
VectorWriter:
Reading/writing from and to
std::vector<std::uint8_t>
, extending as needed when writing