In this tutorial, we demonstrate basics related to setting up and running VLFeat. First, go to here and download the Matlab package. The website has examples of how to install the library. Next, you can get a list (here) of what functions are avilable in Matlab.

**VLFeat "human engineered" LBP features:**

For local binary pattern (LBP) feature, see link1 and link2. Note, Matlab has a nice implementation also (link) that lets you change the radius and normalization and etc (and get down to fewer number of patterns). However, we support VLFeat in this tutorial because it does not require purchasing a toolbox (Matlabs LBP is part of the computer vision toolbox). For a decent overview of the LBP, see link1 and link2. First, we load an image and convert it to grayscale.

```
``````
% load an image in matlab
I = double(imread('peppers.png'));
I = I ./ 255;
figure; imshow(I);
% convert to grayscale
I = rgb2gray(I);
figure; imagesc(I);
```

Next, setup VLFeat.

```
``````
% setup vlfeat
addpath(genpath('C:\VLfeat\vlfeat-0.9.20-bin\vlfeat-0.9.20'));
vl_setup();
```

Next, compute the LBP with cell sizes of 100x100. This means we decompose our image into NxM different spatial cells, where each cell is a histogram summarization of the distribution of LBPs in that spatial region. Note, you can do this with overlapping cells or non-overlapping cells.

```
``````
% extract the LBP histogram (note, the 100 is the cell size, so a square cell here)
F = vl_lbp(single(I),100);
S = size(F)
```

Since we get NxM different cells, I plot them for visual display. However, we typically use these in a support vector machine classifier or something.

```
``````
% plot the histograms
figure;
k=1;
for i=1:S(1)
for j=1:S(2)
hold on;
subplot(S(1),S(2),k);
bar(squeeze(F(i,j,:)));
k=k+1;
end
end
```

You can also compute the LBP per pixel and show the image (looks sort of cool actually!).

```
``````
F = vl_lbp(single(I),1);
Fimg = zeros(size(I));
for i=1:size(I,1)
for j=1:size(I,2)
k = find(squeeze(F(i,j,:))==1);
if(isempty(k)==1)
Fimg(i,j) = 0;
else
Fimg(i,j)=k;
end
end
end
figure; imagesc(Fimg)
```

**VLFeat "human engineered" HOG features:**

For histogram of gradients (HOG) feature, see link. First, we load an image and convert it to grayscale.

```
``````
% load an image in matlab
I = double(imread('peppers.png'));
I = I ./ 255;
figure; imshow(I);
% convert to grayscale
I = rgb2gray(I);
figure; imagesc(I);
```

Next, setup VLFeat.

```
``````
% setup vlfeat
addpath(genpath('C:\VLfeat\vlfeat-0.9.20-bin\vlfeat-0.9.20'));
vl_setup();
```

Next, compute our HOG with 9 orientations and 100x100 size cells. If you want the Dalal Trigg variant simply enter ('variant', 'dalaltriggs').

```
``````
% extract the HOG feature
F = vl_hog(single(I),100,'NumOrientations',9);
S = size(F)
```

Last, like in the LBP above, I plot the histograms for visual display. Again, these are typically fed to a classifier or something.

```
``````
% plot the histograms
figure;
imhog = vl_hog('render', F, 'verbose') ;
clf ; imagesc(imhog) ; colormap gray ;
```