Various utilities for working with images in Python 3. for the mir project
Project description
navalmartin_mir_vision_utils
Various utilities for working with images in the mir project.
Acknowledgements
The project incorporates the following repositories
image-quality
https://github.com/ocampor/image-quality (for BRISQUE)imutils
: https://github.com/PyImageSearch/imutils (for various utilities with OpenCV)
Dependencies
- torch
- torchvision
- numpy
- dataclasses
- Pillow
- matplotlib
- opencv-python
- scipy
- scikit-image
- libsvm
Installation
Installing the utilities via pip
pip install navalmartin-mir-vision-utils
For a specific version use
pip install navalmartin-mir-vision-utils==x.x.x
You can uninstall the project via
pip3 uninstall navalmartin-mir-vision-utils
How to use
Below are some use-case samples. You can find more in the examples.
Using image_utils
from pathlib import Path
from navalmartin_mir_vision_utils.image_utils import (is_valid_pil_image_file, get_pil_image_size,
get_img_files)
if __name__ == '__main__':
image = is_valid_pil_image_file(image=Path("/home/alex/qi3/mir-engine/datasets/cracks_v_3_id_8/train/cracked/img_9_9.jpg"))
if image is not None:
print("The provided image is OK")
image_size = get_pil_image_size(image=image)
print(f"Image size is {image_size}")
else:
print("The provided image is NOT OK")
base_path = Path("/home/alex/qi3/mir-engine/datasets/cracks_v_3_id_8/train/cracked/")
image_files = get_img_files(base_path=base_path)
print(f"There are {len(image_files)} in {base_path}")
Using image_transformers
from pathlib import Path
from navalmartin_mir_vision_utils.image_transformers import pil_image_to_bytes_string
from navalmartin_mir_vision_utils.image_utils import load_img
from navalmartin_mir_vision_utils.image_enums import ImageLoadersEnumType
from navalmartin_mir_vision_utils.image_utils import is_valid_pil_image_from_bytes_string
from navalmartin_mir_vision_utils.image_utils import show_pil_image
if __name__ == '__main__':
image_path = Path("/home/alex/qi3/mir-engine/datasets/cracks_v_3_id_8/train/cracked/img_9_9.jpg")
image = load_img(path=image_path, loader=ImageLoadersEnumType.PIL)
show_pil_image(image=image)
image_bytes = pil_image_to_bytes_string(image=image)
image = is_valid_pil_image_from_bytes_string(image_byte_string=image_bytes)
show_pil_image(image=image)
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.