Search code examples
matlabimage-processingmachine-learningfeature-extractionlbph-algorithm

How to extract LBP features from datasets in Matlab?


I've learnt about how to extract features from a single image as described in this example: https://www.mathworks.com/help/vision/ref/extractlbpfeatures.html

Now I am working with datasets of 1000 images for my matlab project to extract features of bicycle, car and motorbike. I have three separate folders including bicycle, car and motorbike in my dataset. During execution, I am getting error saying,

Error using extractLBPFeatures>parseInputs (line 148)

Expected I to be one of these types:

double, single, int16, uint16, uint8, logical

Instead its type was imageSet.

Error in extractLBPFeatures (line 129)

params = parseInputs(I,varargin{:});

Error in LBP (line 21)

bycycleLBP = extractLBPFeatures(bycycleData,'Upright',false);

What should I do? Below is my sample code ==>

imSet = imageSet('dataset\train','recursive');

bicycleData = imSet(1);
carData = imSet(2);
motorbikeData = imSet(3);

%%Extract LBP Features
bicycleLBP = extractLBPFeatures(bicycleData,'Upright',false);
carLBP = extractLBPFeatures(carData,'Upright',false);
motorbikeLBP = extractLBPFeatures(motorbikeData,'Upright',false);

bicycle = bicycleLBP.^2;
car = carLBP.^2;
motorbike = motorbikeLBP.^2;

figure
bar([bicycle; car; motorbike]','grouped');
title('LBP Features Of bicycle, car and motorbike');
xlabel('LBP Histogram Bins');
legend('Bicycle','Car','Motorbike');

Please help me with my sample code implemented.


Solution

  • Let's look at two variables before you attempt to extract the features.

    >> whos imSet bicycleData
      Name             Size            Bytes  Class       Attributes            
      imSet            1x3              1494  imageSet 
      bicycleData      1x1               498  imageSet 
    

    The variable imSet is a list of 3 imageSet objects. The first represents bicycles, so you properly pull the bicycle imageSet into its own variable bicycleData, which is a singular imageSet. So far so good, but when we look at the documentation for extractLBPFeatures...

    features = extractLBPFeatures(I,Name,Value)

    I — Input image

    Input image, specified as an M-by-N 2-D grayscale image that is real, and non-sparse.


    This function can only extract the features of one grayscale image at a time. You'll have to iterate through your imageSet to extract the features one at a time.

    % Create a cell array to store features per image.
    bicycleFeatures = cell(size(bicycleData.ImageLocation));
    
    for i = 1:length(bicycleFeatures)
        % Read in individual image, and convert to grayscale to extract features.
        image = imread(bicycleData.ImageLocation{i});
        bicycleFeatures{i} = extractLBPFeatures(rgb2gray(image));
    end
    

    Keep in mind that you'll still have post-processing work to do. This extracts the features of each image, so you'll have to determine how you want to combine the feature data across each data set.