Collection of console tools for image processing. The ImageTools repository contains scripts for perfoming:
- Individual image processing located under ImageTools
- Batch processing: the scripts perform a transformation of all the images inside a folder and subfolders. The result are placed inside a new folder with the same name as the source directoru plus '_out'. The scripts are located on ImageTools/Batch.
- Datasets: Tools for Machine Learning image datasets processing.
Run the scripts following the next pattern:
python -m ImageTools.Batch.script_name -A --args /image/path.png
Scripts for performing image processing of all the images located under a folder and sub-folders.
Generate a transparency image and save as PNG. Automatic background subtraction from plain colors. Four backround colors: White, black, green and auto. Im auto mode: the foreground detection is based on the most common color of the image. Example auto mode transparency generator:
python -m ImageTools.Batch.create_png [-s] [-c COLOR] [-x] path
path: Image path or directory containing images
-s, --show Show changes on image for visual debugging
-c COLOR, --color Background color of the image, available: white, black, green or auto
-x, --convex_hull Get alpha channel with convex hull
Batch crop part of all the images located in a folder and subfolders. There are available 4 ways to crop the images:
- Square centered: crop a square centered of the image with a specified size
- Y-axis range: crop a range of the image in the y-axis
- X-axis range: crop a range of the image in the x-axis
- Automatic: crop arrount the largest blob in the alpha channel
Image cropper examples:
python -m ImageTools.Batch.cropper [-s SIZE] [-y YRANGE] [-x XRANGE] [-q QUALITY] [-a] path
path : Source directory
-s SIZE, --size Size of the side cropped area centered on the image
-y YRANGE, --yrange Range of image in y axis (y_init, y_final)
-x XRANGE, --xrange Range of image in x axis (x_init, x_final)
-q QUALITY, --quality Output file image quality
-a, --auto Crop automatic based alpha channel
Scale all the images inside folder and subfolders. This script creates a new folder in the same location with the same name plus '_resized'.
python -m ImageTools.Batch.resize [-h] [-s SCALE] [-q QUALITY] path
path Image path or directory containing images
-s SCALE, --scale Scale both widht and height
-q QUALITY, --quality Output file image quality
Generate a transparency image by removing the background using two images (Background and Foreground) and save as PNG.
python -m ImageTools.png_from_ims [-h] [-t THRESHOLD] [-m MIN] [-s] [-c] [-b] [-u] im0 im1
im0 Path to background image
im1 Path to foreground image
-t THRESHOLD, --threshold Percentage of pixels that changed to be considered a change
-m MIN, --min Minimum pixel chamge to be considered
-s, --show Show changes on image for visual debugging
-c, --crop Crop image around largest contour
-b, --background Keep image background
-u, --hull Use convex hull for mask generation
When used for batch processing the images inside the folders the name most be ended in '_0' in background and '_1' and the same arguments are available.
Add gaussian blur to all images located in folder and subfolders. Creates an output folder located in the same root location with the same as the source.
python -m ImageTools.Batch.blur [-h] [-k KERNELSIZE] path
path Image path or directory containing images
-k KERNELSIZE, --kernelSize Blur filter kernel size (k,k)
Creates a new image by cropping the area of foreground that changes between foreground and background.
python -m ImageTools.Batch.crop_change [-h] [-t THRESHOLD] [-m MIN] [-s] [-u] im0 im1
im0 Path to background image
im1 Path to foreground image
-t THRESHOLD, --threshold Percentage of pixels that changed to be considered a change
-m MIN, --min Minimum pixel chamge to be considered
-s, --show Show changes on image for visual debugging
-u, --hull Use convex hull for mask generation
Tools for Machine Learning image datasets processing.
Generate transparency image using COCO segmentation labels
Scripts for performing color and shape image analysis
Calculates and display image color histogram
python -m ShowHistogram [-h] im_path