Image Cleaning with Data Separation.

Adejoke Ogundipe
3 min readJun 15, 2021

--

What have you been desperate to learn, is it programming or other things. Well, if python let us walk through this together.

shutterstock.com

Problem: sorting out of bad images from sample images, write the properties of the bad images from a csv file into a text file.

The steps to follow for beginners in python like me is:

Firstly, install python, install anaconda you can check this link for the installation of anaconda on any operating system.

https://docs.anaconda.com/anaconda/install/windows/

Anaconda support various IDEs and editors. While installing anaconda click on the option “add to path”. It is very essential because I made that mistake when I started.

After the installation of anaconda, install pandas a general library for data manipulation. You can use pip install function to install necessary packages.

Solution

Step1: Importation of all libraries needed in python.

Libraries imported.

Step2: Navigate to the path where the folders are located or saved on the pc.

paths to the needed folders and files

Where the “start-time” is tracking the execution time of all the processes in the script.

Step3: Read the csv file , if need arises for csv file or you can convert a text file or an excel file to csv file by using the image below or use google.

conversion of excel file to csv

The next image shows the reading of csv to data frame and manipulating the columns.

reading csv and getting the needed columns from the Data frame.

Step4: Loop through the root directory and files to check the validity of the images, if any with bad: resolution, shape, size or naming convention are all classified as bad images.

Loop for all folders and files in the directory.

or use this to count all folders and files available in the directory

path is declared before hand.
conditions checked on the images.

Step5: If any of the conditions are not true, move the bad images to another path, by creating a new folder with the formal folder name and write the properties of the images from a data frame into a text file concurrently.

else function for the bad images.

Thanks for walking with me to the end of this project. For the source code you can check

https://github.com/AdejokeOgundipe/ImageCleaning.git.

Thanks.

--

--

Adejoke Ogundipe

An explorer of tech world, a learner, an epigrammatist and a rare gem..