Package: simpleimageio
Simple Image IOA lightweight C# and Python wrapper to read and write RGB images from / to various file formats.
Supports .exr (with layers) viatinyexrand a number of other formats (including .png, .jpg, and .bmp) viastb_imageandstb_image_write.
A subset of TIFF can be read and written viatinydngloader.
We also implement our own importer and exporter forPFM.
In addition, the package offers some basic image manipulation functionality, error metrics, and tone mapping.The C# wrapper further offers utilities for thread-safe atomic splatting of pixel values, and sending image data to thetevviewer via sockets. It also contains a very basic wrapper aroundIntel Open Image Denoise.TheNuget packagecontains prebuilt binaries of the C++ wrapper for x86-64 Windows, Ubuntu, and macOS (.github/workflows/build.yml).
ThePython packageis set up to automatically download an adequate CMake version and compile the C++ code on any platform.Except for the optional Intel Open Image Denoise, all dependencies are header-only and unintrusive, so this library should work pretty much anywhere without any hassle.Usage example (C#)The following creates a one pixel image and writes it to various file formats:RgbImageimg=new(width:1,height:1);img.SetPixel(0,0,new(0.1f,0.4f,0.9f));img.WriteToFile("test.exr");img.WriteToFile("test.png");img.WriteToFile("test.jpg");Reading an image from one of the supported formats is equally simple:RgbImageimg=new("test.exr");Console.WriteLine(img.GetPixel(0,0).Luminance);The pixel coordinate (0,0) corresponds to the top left corner of the image. Coordinates outside the valid range are clamped automatically; no error is raised. The framework also offers aMonochromeImagewith a single channel per pixel. Further, the base classImageBasecan be used directly for images with arbitrary channel count (RgbImageandMonochromeImageonly add some convenience functions like directly returning anRgbColorobject).As an added bonus, the C# wrapper can connect to thetevHDR viewer and directly display image data via sockets. The following example generates a monochrome image and sends it to tev:TevIpctevIpc=new();// uses tev's default port on localhost// Create the image and initialize a tev syncMonochromeImageimage=new(width:20,height:10);tevIpc.CreateImageSync("MyAwesomeImage",20,10,("",image));// Pretend we are a renderer and write some image data.image.SetPixel(0,0,val:1);image.SetPixel(10,0,val:2);image.SetPixel(0,9,val:5);image.SetPixel(10,9,val:10);// Tell the TevIpc class to update the image displayed by tev// (this currently retransmitts all pixel values)tevIpc.UpdateImage("MyAwesomeImage");Usage example (Python)The following creates a one pixel image, writes it to various file formats, reads one of them back in, and prints the red color channel of the pixel.
The result is then sent to thetevHDR viewer via sockets (modified version ofhttps://gist.github.com/tomasiser/5e3bacd72df30f7efc3037cb95a039d3).importsimpleimageioassiosio.write("test.exr",[[[0.1,0.4,0.9]]])sio.write("test.png",[[[0.1,0.4,0.9]]])sio.write("test.jpg",[[[0.1,0.4,0.9]]])img=sio.read("test.exr")print(img[0,0,0])withsio.TevIpc()astev:tev.display_image("image",img)tev.display_layered_image("layers",{"stuff":img,"morestuff":img})In Python, an image is a 3D row-major array, where[0,0,0]is the red color channel of the top left corner.
The convention is compatible with most other libraries that make use of numpy arrays for image representation, like matplotlib.Flip books for Jupyter and webBoth, the Python and the .NET library can generate an interactive HTML viewer to display and compare images visually by flipping between them. SeeFlipBookExample.dibfor an example with .NET interactive and C#,FlipBookExample.fsxfor a static webpage generator with F#, orflipbook.ipynbfor a Jupyter notebook with Python.Building from sourceIf you are on an architecture different from x86-64, you will need to compile the C++ wrapper from source.
Below, you can find instructions on how to accomplish that.DependenciesAll dependenciesexcept OIDNare header-only and included in the repository. Building requiresa C++20 compilerCMake.NET 6.0(or newer)Python ≥ 3.6Building the C# wrapper - quick and simplepwsh ./make.ps1Downloads precompiled binaries for Open Image Denoise, copies them to the correct directory, builds the C++ code and then builds and tests the C# wrapper.Building the C# wrapper - manuallyBuild the C++ low level library withCMake:mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
cd ..If you want to use theDenoiserclass, compiled binaries of Open Image Denoise must be in the correctruntimesfolder. For example, on x64 Linux, there should be alibOpenImageDenoise.soinruntimes/linux-x64/native/. See the copy operations inmake.ps1for details. The project works without these binaries in place, but then any attempt to use theDenoiserclass will result in aDllNotFoundexception at runtime.When using binaries, especially the official ones, be aware that packaging for .NET requires the RPATH of the shared library to include the same folder that contains the library itself. Otherwise, TBB will not be found. If you don't understand what that means, or how it can be achieved, check out the build script inRenderLibs. (This does not apply to Windows, since the linker there has this behavior by default.)Build the C# wrapper and run the tests:dotnet build && dotnet testTo see if the denoiser is linked correctly, you can additionally rundotnet run --project SimpleImageIO.IntegrationThese integration tests assume that you have thetevviewer open and listening to the default port on localhost. But you can also comment out the tev-related tests and only run the denoiser ones.Building the C# wrapper on other platformsTheSimpleImageIO.csprojfile needs to copy the correct .dll / .so / .dylib file to the appropriate runtime folder.
Currently, the runtime identifiers (RID) and copy instructions are only set for the x86-64 versions of Windows, Linux, and macOS.
To run the framework on other architectures, you will need to add them to the .csproj file.
You can find the right RID for your platform here:https://docs.microsoft.com/en-us/dotnet/core/rid-catalog.Note that, currently, Open Image Denoise is included in binary from. TheDenoiserclass can therefore not be used on platforms other than x86-64 Windows, Linux, or macOS. Attempting to use it on other platforms will cause aDllNotFoundexception.Then, you should be able to follow the steps above and proceed as usual.Building the Python wrapperThe simplest route is to run the build scriptpwsh ./make.ps1which builds and installs the Python lib with pip, using whateverpythonexecutable is currently in the path.If you need manual control, e.g., specific Python version, here are the required steps:cd ./FlipViewer
npm install
npm run build
cd ..
cp ./FlipViewer/dist/flipbook.js PyWrapper/simpleimageio/flipbook.js

python -m build
python -m pip install ./dist/simpleimageio-*.whlThe first commands build, bundle, and pack the frontend code. Then, we build the Python package itself and install it via pip. The*must be substituted by the correct version number and runtime identifier.The tests can be run via:cd PyTest
python -m unittest