Simple image tools package. Used to convert, downscale or upscale images.
Project description
imgtools_m8
Simple image tools package. Used to convert, downscale and/or upscale images.
Use deep learning and cv2 to upscale image using Xavier Weber models, (more info here).
Installation
Install from GitHub repository :
To install directly from GitHub:
$ python3 -m pip install "git+https://github.com/mano8/imgtools_m8"
How to use
This package automatically covert, downscale and/or upscale
an image file or a list of images from directory defined in source_path property.
(See accepted extensions from cv2 documentation)
Example :
>>> # Set source as an image file
>>> source_path = /path/to/image.png
>>> # Or set source as a directory containing your images
>>> source_path = /path/to/directory
Next you will need to define output configuration:
- path: The output path
- output_formats: The list of output formats,
who contains optional output sizes and output image format
(extension and compression options)
It is possible to resize images with different options:
- fixed_width: resize image to exact width (in pixel)
- fixed_height: resize image to exact height (in pixel)
- fixed_size: resize image depending on first limitation reached (height or width)
- fixed_width and fixed_height: resize image depending on first limitation reached.
same as fixed_size but can set different height/width values.
Example : The source file is 450px width and 280px height. You want resized output file to exact width of 1600px and 800px. And you need output formats as JPEG (with 80% quality) and WEBP (with 70% quality)
>>> source_path = /path/to/image.png
>>> output_conf = {
# Output path
'path': /my/output/path/directory,
'output_formats': [
{ # Get resized output file to exact width of 1600px
'fixed_width': 1600,
'formats': [
# JPEg defauts are 'quality': 95, 'progressive': 0, 'optimize': 0
{'ext': '.jpg', 'quality': 80, 'progressive': 1, 'optimize': 1},
{'ext': '.webp', 'quality': 70},
{'ext': '.png', 'compression': 2}
]
},
{ # Get resized output file to exact width of 800px
'fixed_width': 800,
'formats': [
{'ext': '.jpg', 'quality': 80},
{'ext': '.webp', 'quality': 70}
]
}
]
}
>>> imgtools = ImageTools(
source_path=source_path,
output_conf=output_conf
)
>>> imgtools.run()
This will create 4 files in the output directory :
- Two JPEG files resized as defined width (1600px and 800px), with 80% quality, JPEG progressive and optimize features enabled
- Two WEBP files resized as defined width (1600px and 800px), with 70% quality
- One PNG file resized as defined width (1600px), with PNG compression level = 2
The output file names are set as:
>>> 'originalName'_'imageWidth'x'imageHeight'.'outputExtension'
>>> # egg :
>>> originalFileName_1400x1360.jpeg
In this case source file is precessed as:
- upscale 2x (source file is now 900px/560px)
- for 800px width output downscale and save as .jpeg an .webp
- upscale 2x (source file is now 1800px/1120px)
- for 1600px width output downscale and save as .jpeg an .webp
By default, the image tool use EDSR_x2.pb deep learning model, to improve quality.
To load any compatible model of your choice to upscale the images, you can define model_conf property.
The imgtools_m8 only contain EDSR (x2, x3, x4) and FSRCNN(x2, x3, x4) models.
If you want uses one of them set model_conf property as:
>>> # Set EDSR_x4 model to upscale images
>>> model_conf = {
'file_name': 'EDSR_x4.pb',
}
>>> # Or set FSRCNN_x2 model to upscale images
>>> model_conf = {
'file_name': 'FSRCNN_x2.pb',
}
In case you want uses
another compatible model,
you may download the desired .pb
file,
and set model_conf property as:
>>> # Set TF-ESPCN_x2 model to upscale images
>>> model_conf = {
'path': "/path/to/your/downloaded/model/directory",
'file_name': 'TF-ESPCN_x2.pb',
}
Here a complete example using TF-ESPCN_x2 model to upscale images :
>>> # Set TF-ESPCN_x2 model to upscale images
>>> model_conf = {
'path': "/path/to/your/downloaded/model/directory",
'file_name': 'TF-ESPCN_x2.pb',
}
>>> source_path = /path/to/image.png
>>> output_conf = {
# Output path
'path': /my/output/path/directory,
'output_formats': [
{ # Get resized output file to exact width of 1600px
'fixed_width': 1600,
'formats': [
{'ext': '.jpg', 'quality': 80},
{'ext': '.webp', 'quality': 70}
]
},
{ # Get resized output file to exact width of 800px
'fixed_width': 800,
'formats': [
{'ext': '.jpg', 'quality': 80},
{'ext': '.webp', 'quality': 70}
]
}
]
}
>>> imgtools = ImageTools(
source_path=source_path,
output_conf=output_conf,
model_conf=model_conf
)
>>> imgtools.run()
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
Built Distribution
File details
Details for the file imgtools_m8-0.0.2.tar.gz
.
File metadata
- Download URL: imgtools_m8-0.0.2.tar.gz
- Upload date:
- Size: 94.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6425352f8b1e8e87947cb1a71b06d7995dd5d67ab6ddd73354580f84d6958cb |
|
MD5 | dd1e684a2650bae31e7bf213e78bc63a |
|
BLAKE2b-256 | f99263cc29612e4b3c259e5d13daab987514015b6090874c57c034693db395eb |
File details
Details for the file imgtools_m8-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: imgtools_m8-0.0.2-py3-none-any.whl
- Upload date:
- Size: 94.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de71d64c2afd9c2e76030ea55d1e189e1950732a014c575a598fe1c75e2ca4c |
|
MD5 | 9d5020b14ab229e101f8bc1b9c334bba |
|
BLAKE2b-256 | adea91388039bcb1edf62ae282a14d05d24e8e0b9cb02e98d88c0eee071b3d53 |