local-descriptors-for-image-classification

Local Descriptors

View the Project on GitHub vdevmcitylp/local-descriptors-for-image-classification

local-descriptors-for-image-classification

UPDATE: My paper has been accepted! Check it out here.

Each file implements one of the variants of the Local Binary Pattern (LBP).

  1. Center Symmetric LBP
  2. Center Symmetric Local Derivative Pattern
  3. Center Symmetric Local Derivative Mapped Pattern
  4. Center Symmetric Local Mapped Pattern
  5. Center Symmetric Local Ternary Pattern
  6. Extended Center Symmetric Local Binary Pattern
  7. Extended Center Symmetric Local Mapped Pattern
  8. Extended Center Symmetric Local Ternary Pattern

Setup

Environment

- Python 3.7.6
- Ubuntu 16.04

Preferably, create a new environment using virtualenv.

Requirements

After activating the virtual environment, run the following command to install dependencies.

pip install -r requirements.txt

Datset Setup

Download the CIFAR-10 dataset from here and extract in the dataset directory.

For CIFAR-10, run this command to convert the images to grayscale.

python data_helper.py

This is a helper function for loading, preprocessing and saving the preprocessed images to disk for the CIFAR-10 dataset

Please write your own function for a custom dataset which,


All the files in operators/ have the same underlying structure with the only difference being in the algorithm being implemented. All algorithms are trained and tested on the CIFAR-10 dataset.

To compute features

python main.py --operator cslbp --img_height 32 --img_width 32

The above command will compute CS-LBP features, check the operator argument for more choices.

Brief Explanation

Converting to Grayscale

These local descriptors require the input to be in grayscale.

grayscaleImg = (imRed*0.3 + imGreen*0.59 + imBlue*0.11).astype(int)

The Algorithm

First, I pad the image with zeros before running the algorithm.

img = np.concatenate((img, zeroVertical), axis=1)
img = np.concatenate((zeroVertical, img), axis=1)
img = np.concatenate((zeroHorizontal, img), axis=0)
img = np.concatenate((img, zeroHorizontal), axis=0)

The function then goes on to implement the respective algorithm (CS-LBP in this case).

pattern_img = np.zeros((img_height + 1, img_width + 1))
    
    for x in range(1, img_height + 1):
        for y in range(1, img_width + 1):
            
            s1 = threshold(img[x-1, y-1] - img[x+1, y+1])
            s2 = threshold(img[x-1, y] - img[x+1, y])*2 
            s3 = threshold(img[x-1, y+1] - img[x+1, y-1])*4 
            s4 = threshold(img[x, y+1] - img[x, y-1])*8

            s = s1 + s2 + s3 + s4

            pattern_img[x, y] = s

We then compute the histogram of the resultant image to get the feature vector.

histogram = np.histogram(pattern_img, bins = np.arange(17))[0]

Classification

python classification.py --operator cslbp

I’m using the XGBoost Classifier for classification.

model = XGBClassifier(n_estimators=800)
model.fit(X_train, y_train)

You have to play with n_estimators to get the best accuracy.

And that’s about it! Feel free to open an issue if required.