MATLAB Answers

1

uniform local binary pattern

Asked by jenifer on 6 Oct 2012
Latest activity Commented on by rsnandi
on 24 Jul 2018
i need a matlab source code for "uniform local binary pattern" for textural features..

  0 Comments

Sign in to comment.

4 Answers

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);

  10 Comments

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
Because localBinaryPatternImage is a double. And for double arrays, imhist() expects that they will be in the range 0-1. But our localBinaryPatternImage is in the range 0-255. So all values from 1 to 255 will show up in the highest bin - the 256th bin. The count for the zeros will show up in the left bin at index 1. So the histogram will show only two bins, at each extreme end. If you cast it from double to uint8, then imhist() will assume that the bins go from 0 - 255 instead of 0-1 and the histogram will be calculated correctly.
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,[]);

  1 Comment

Image Analyst
on 26 Sep 2014
Essentially a more compact version of mine with one difference. You set the bit if it equals the center pixel, while I followed http://en.wikipedia.org/wiki/Local_binary_patterns, which says " Where the center pixel's value is greater than the neighbor's value, write "1". Otherwise, write "0". " and do not set the bit. Why did you choose to set the bit differently?

Sign in to comment.


Answer by As Has on 6 Feb 2017

how can i compute the features after these statement

  0 Comments

Sign in to comment.


Answer by sonu Lamba on 21 Jul 2017

I need to understand dynamic texture by local binary pattern and how to extract LBP feature for videos?. Here I am not getting the spatio-temporal meaning of feature and how to visualize them?

  0 Comments

Sign in to comment.