Asked by jenifer
on 6 Oct 2012

i need a matlab source code for "uniform local binary pattern" for textural features..

Answer by Image Analyst
on 6 Oct 2012

Accepted Answer

I don't know what "uniform" means with respect to LBP, but here is my demo for LBP, for what it's worth:

clc; % Clear the command window.

close all; % Close all figures (except those of imtool.)

imtool close all; % Close all imtool figures.

clear; % Erase all existing variables.

workspace; % Make sure the workspace panel is showing.

fontSize = 20;

% Read in a standard MATLAB gray scale demo image.

folder = fullfile(matlabroot, '\toolbox\images\imdemos');

baseFileName = 'cameraman.tif';

% Get the full filename, with path prepended.

fullFileName = fullfile(folder, baseFileName);

if ~exist(fullFileName, 'file')

% Didn't find it there. Check the search path for it.

fullFileName = baseFileName; % No path this time.

if ~exist(fullFileName, 'file')

% Still didn't find it. Alert user.

errorMessage = sprintf('Error: %s does not exist.', fullFileName);

uiwait(warndlg(errorMessage));

return;

end

end

grayImage = imread(fullFileName);

% Get the dimensions of the image. numberOfColorBands should be = 1.

[rows columns numberOfColorBands] = size(grayImage);

% Display the original gray scale image.

subplot(2, 2, 1);

imshow(grayImage, []);

title('Original Grayscale Image', 'FontSize', fontSize);

% Enlarge figure to full screen.

set(gcf, 'Position', get(0,'Screensize'));

set(gcf,'name','Image Analysis Demo','numbertitle','off')

% Let's compute and display the histogram.

[pixelCount grayLevels] = imhist(grayImage);

subplot(2, 2, 2);

bar(pixelCount);

title('Histogram of original image', 'FontSize', fontSize);

xlim([0 grayLevels(end)]); % Scale x axis manually.

% Preallocate/instantiate array for the local binary pattern.

localBinaryPatternImage = zeros(size(grayImage));

for row = 2 : rows - 1

for col = 2 : columns - 1

centerPixel = grayImage(row, col);

pixel7=grayImage(row-1, col-1) > centerPixel;

pixel6=grayImage(row-1, col) > centerPixel;

pixel5=grayImage(row-1, col+1) > centerPixel;

pixel4=grayImage(row, col+1) > centerPixel;

pixel3=grayImage(row+1, col+1) > centerPixel;

pixel2=grayImage(row+1, col) > centerPixel;

pixel1=grayImage(row+1, col-1) > centerPixel;

pixel0=grayImage(row, col-1) > centerPixel;

localBinaryPatternImage(row, col) = uint8(...

pixel7 * 2^7 + pixel6 * 2^6 + ...

pixel5 * 2^5 + pixel4 * 2^4 + ...

pixel3 * 2^3 + pixel2 * 2^2 + ...

pixel1 * 2 + pixel0);

end

end

subplot(2,2,3);

imshow(localBinaryPatternImage, []);

title('Local Binary Pattern', 'FontSize', fontSize);

subplot(2,2,4);

[pixelCounts, GLs] = imhist(uint8(localBinaryPatternImage));

bar(GLs, pixelCounts);

title('Histogram of Local Binary Pattern', 'FontSize', fontSize);

Halina H
on 14 Dec 2017

Hi , I would like to know why for the original image you use [pixelCount grayLevels] = imhist(grayImage); but for the LBP Image , you use [pixelCounts, GLs] = imhist(uint8(localBinaryPatternImage));

My question is , why for the LBP image histogram, imhist need to be in uint8.

Thanks

Image Analyst
on 14 Dec 2017

rsnandi
on 24 Jul 2018

thanks alot sir

Sign in to comment.

Answer by anusha
on 24 Sep 2014

Edited by anusha
on 26 Sep 2014

lbp code

clear all; close all; I=imread('cameraman.tif'); I=rgb2gray(I); I1=imcrop(I); [w h]=size(I1);

for i=2:w-1 for j=2:h-1 val=I1(i,j); scale=2.^[0 1 2;7 -inf 3;6 5 4]; mat=[I1(i-1,j-1) I1(i-1,j) I1(i-1,j+1);I1(i,j-1) I1(i,j) I1(i,j+1);I1(i+1,j-1) I1(i+1,j) I1(i+1,j+1)]; mat=mat>=val; fin=mat.*scale; I1(i,j)=uint8(sum(sum(fin))); end end imshow(I1,[]);

Image Analyst
on 26 Sep 2014

Sign in to comment.

Answer by sonu Lamba
on 21 Jul 2017

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.