Renames, Crops, Resizes images on to a white background using python Contours
Automate image processing using python and OpenCV.
These scripts will in bulk:
Run each of these scripts to launch a gui app.
You can also run the .ipynb versions on Google Colabs.
To run on your workstation, you will need to install python from https://www.python.org/
When prompted, make sure to set python to PATH and install PIP.
mkdir myprojectname
cd myprojectname
git clone https://github.com/snowyTheHamster/autoImageRenameCropResize.git .
python -m venv .venv
Active the virtual Env in Mac and Linux:
. .venv/bin/activate
Active the virtual Env in Windows:
. .venv/script/activate
python -m pip install --upgrade pip
pip install -r requirements.txts
python 1removebg_upgraded.py
NOTE: Detecting white objects against a white background is difficult.
To maximize the success rate, try to blowing out your white background during the photo shoot.
Keep your object’s edges as distinct from the background as possible.
Installing the GUI app
to install this script as a gui app, run the following commands:
pyinstaller --onefile 1removebg_upgraded.py
The executable app will be saved in the dist folder for your operating system.
NOTE 2: You can change the parameters if the defaults don’t yield good results.
python 2cropimg.py
This script will detect the edges of the object in the images and crop around the edges.
You can add extra paddings by changing the settings.
python 3resizeimg.py
This script essentially creates a new image (white background) in the desired size and pastes the original image into it.
This script does not alter the input folder so you can experiment with it.
python 4renamefiles.py
Note
Scenario 1
60 images, 1 angle(s) per image, set no. per file to 1 -> csvfile will contain 60 rows of filename.
output will be: row1name_1.jpg, row2name_1.jpg, row3name_1.jpg, row4name_1.jpg etc..
Scenario 1
60 images, 2 angle(s) per image, set no. per file to 2 -> csvfile will contain 30 rows of filename.
output will be: row1name_1.jpg, row1name_2.jpg, row2name_1.jpg, row2name_2.jpg etc..
Note 2
These scripts won’t affect the original images but you should still make back ups.