Skip to main content

A image toolkit designed to convert the image file from any supported type to another one with only one line code.

Project description

FaYE-image

A image toolkit designed to convert the image file from any supported type to another one with only one line code.

current supported file types:

  • .png
  • .jpg / .jpeg
  • .exr
  • .gif
  • .npy

current supported runtime data types:

  • numpy.ndarray
  • torch.Tensor
  • cv2.Mat
  • PIL.Image.Image
  • matplotlib.pyplot.Figure

News

  • 2021.10.12: FaYE 0.2.0 is released, bringing a totally new version of FaYE-image, with more operations and easier interfaces.

Requirement

Necessary packages

  • numpy

Optional packages

  • matplotlib
  • PIL
  • opencv-python
  • torch
  • OpenEXR

Usage

Installation:

pip install faye-image

To achieve this easy and uniform image data IO operations, you only need to add:

from faye_image import *

at the beginning of your code.

If you want to load a PNG image file into a torch tensor, you can simply call:

tensor = Convert('path/to/image.png', from_type=PNG_FILE, to_type=TORCH)

Or precisely version:

intermediate = From('path/to/image.png', data_type=PNG_FILE)
tensor = To(intermediate, data_type=TORCH)

If you want to save a torch tensor to a PNG image file, you can simply call:

Convert(tensor, from_type=TORCH, to_type=PNG_FILE, save_path='path/to/image.png', save_mode='RGB')

Or precisely version:

intermediate = From(tensor, data_type=TORCH)
To(intermediate, data_type=PNG_FILE, save_path='path/to/image.png', save_mode='RGB')

If you want to convert a numpy image data to a cv::Mat, you can simply call:

mat = Convert(numpy_image, from_type=NUMPY, to_type=CV_MAT)

Or precisely version:

intermediate = From(numpy_image, data_type=NUMPY)
mat = To(intermediate, data_type=CV_MAT)

Extension

If you want to make this module compatible with more image data types of your interest, you just need to implement a corresponding builder class inherited from the ImageDataBuilder class.

Then, call the RegisterBuilders(builder1, builder2, ...) at the end of your .py file to add the builder to the image factory.

The builder class should implement the following methods:

  • CanBuild(data) -> bool: Check if the builder can build the data.
  • GetTag() -> str: Get the tag of the builder.
  • BuildIntermediate(data) -> ImageIntermediate: Build the image intermediate from the data. For current version, the image intermediate is a numpy array in [BxCxHxW] in float32.
  • BuildData(intermediate: ImageIntermediate, **kwargs): Build the data from the image intermediate. Since the B maybe not 1, the batch dimension should be considered in the implementation. Returning a list of data is also supported.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faye_image-0.2.1.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faye_image-0.2.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file faye_image-0.2.1.tar.gz.

File metadata

  • Download URL: faye_image-0.2.1.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for faye_image-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e8c026898b9f3d8c9980569c2c696281befb63e4f3f802b02916b61eeb3522b7
MD5 d1e1151248db7a0f05cc59ef2aea7027
BLAKE2b-256 1101002a8650d93131a16c90e2d75d3783f4d73630fe0b3d55192f422469fd85

See more details on using hashes here.

File details

Details for the file faye_image-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: faye_image-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.5

File hashes

Hashes for faye_image-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a75a8e463e346aaaaef49c2283cdd6cc40c78a46dba690d6335bb9941777dc8c
MD5 27a8a0b9d71a3df57176a06641826823
BLAKE2b-256 d32efec54e1d292fd52990c1363852b5bd70fd29a3621c9f29c4089828fe2e95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page