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
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 imageIO 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\]infloat32.BuildData(intermediate: ImageIntermediate, **kwargs): Build the data from the image intermediate. Since theBmaybe not 1, the batch dimension should be considered in the implementation. Returning a list of data is also supported.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file faye_image-0.1.0.tar.gz.
File metadata
- Download URL: faye_image-0.1.0.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
467285d57fb18ad9712f833e5d8102262d291b00bf8be3b558b0d18564f434b2
|
|
| MD5 |
64580fed72217d891947de50278d3af5
|
|
| BLAKE2b-256 |
3b9dced490928654615c8105aebba798bdf97f9beeaeeac7a7532c0ebfbf528c
|
File details
Details for the file faye_image-0.1.0-py3-none-any.whl.
File metadata
- Download URL: faye_image-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
579983dda09b44ee5f360dc93e2418ac912ee71bddcf0b872898ffe1966b0630
|
|
| MD5 |
8277c13786ed9ca86beb91bc5278c2e7
|
|
| BLAKE2b-256 |
632e6911447ebb1f4514e7ce0713e074786b36148153f4477b69d2e377dd3581
|