imageio plugin with FLIF wrapper for Python
Code repository here: https://codeberg.org/monilophyta/imageio-flif
The purpose of this project is to provide a simple python wrapper for the FLIF image compression. It implements a simple plugin for the imageio library that enables reading and writing FLIF image files.
FLIF supports lossy and lossless compression for 8bit and 16bit gray scale and RGB(A) images. The lossless compression mode outperforms PNG, lossless WebP, lossless BPG and lossless JPEG 2000 in terms of compression ratio.
Like GIF, FLIF files support animations by storing mutliple frames within one .flif
file.
image shape | depth | reading | writing | |
---|---|---|---|---|
Gray scale | [WxH] | 8bit | ✅ | ✅ |
Gray scale | [WxH] | 16bit | ✅ | ✅ |
RGB | [WxHx3] | 8bit | ✅ | ✅ |
RGB | [WxHx3] | 16bit | ✅ | ❌ |
RGBA | [WxHx4] | 8bit | ✅ | ✅ |
RGBA | [WxHx4] | 16bit | ✅ | ❌ |
Palette color (quantized) images |
[WxH] | 8bit | ✅ | ✅ |
imageio-FLIF
imports the FLIF library as a sub-module. Please have a look here for FLIF library dependencies.
- numpy:
sudo apt-get install python3-numpy
(on debian/ubuntu) - imageio:
sudo apt-get install python3-imageio
(on debian/ubuntu)
git clone https://codeberg.org/monilophyta/imageio-flif.git imageio_flif
cd imageio_flif
git submodule init
git submodule update
make
# import imageio framework for image reading/writing
import imageio
# imported FLIF plugin registers itself at the imageio framework
import imageio_flif
# returns a uint8 or uint16 numpy array of shape [WxH(x3/4)]
img = imageio.imread( "path_to/image.flif" )
# return a list with each item a equal shaped array with dtype uint8 or uint16
img_list = imageio.mimread( "path_to/image.flif" )
# img must be an uint8 or uint16 numpy array with shape [WxH(x3/4)]
imageio.imwrite( "path_to/image.flif", img )
# img must be a list of equal shaped [WxH(x3/4)] numpy arrays, all of them with dtype uint8 or uint16 [WxH(x3/4)]
imageio.mimwrite( "path_to/image.flif", img_list, duration=N )