Thursday 23 March 2017

Feret Database PreProcessing Script

I am currently working with the Feret Database on Age Determination using Frontal Facial Images using KNN and LBP in Python 3 and OpenCV.

However the Feret Database comes in a tar which when extracted contains a large number of ppm files in bz2 archives which need to be converted into jpegs before any further processing can take place.

I wrote this script in case. I am sure it will be useful to other people working with the Feret Database.



Script

#FAD-FACE AGE DETERMINATION
#Feret Preprocessor
#ABHISHEK MUNAGEKAR
#ALL RIGHTS RESERVED
#This module was tested on
#Platform: x86_64
#Os: Manjaro Linux
#PythonEnvironment:Python3.x
#Editor/IDE used: Geany

import sys
import os
from PIL import Image
#give the folder numbers to be processed
for i in range (740,1209):
    stringi=str(i)
    while len(stringi) != 5:
        stringi='0'+stringi
    stringi= stringi + '/'
    #feret database path
    folder='/fertetdatabasepath/dvd2/data/images/'+stringi
    print ('****'+folder+'***')
    if not os.path.isdir(folder):
        print(folder,'does not exist************')
        continue;
    files= os.listdir(folder)


    for path in files:
        path=(folder + path).strip()
        os.system('bzip2 -d '+path )
        path=path.split(".")[0]+'.ppm'
        print ("Processing image:",path)
        im=Image.open(path)
        newpath=path.split(".")[0] + '.jpg'
        im.save(newpath)
        os.remove(path)

No comments:

Post a Comment