2014-03-04 8 views
3

저는 Matlab을 사용하여 Local Binary Patterns를 구현하고 있습니다. 저는 약간 혼란 스럽습니다. num_cels 이미지의 16x16 픽셀 세포의 수입니다 Local Binary Patters matlab의 원본 코드 및 참조

1- Divide the examined window into cells (e.g. 16x16 pixels for each cell). 
2- For each pixel in a cell, compare the pixel to each of its 8 neighbors (on its left-top, left-middle, left-bottom, right-top, etc.). Follow the pixels along a circle, i.e. clockwise or counter-clockwise. 
3- Where the center pixel's value is greater than the neighbor's value, write "1". Otherwise, write "0". This gives an 8-digit binary number (which is usually converted to decimal for convenience). 
4- Compute the histogram, over the cell, of the frequency of each "number" occurring (i.e., each combination of which pixels are smaller and which are greater than the center). 
5- Optionally normalize the histogram. 
6- Concatenate (normalized) histograms of all cells. This gives the feature vector for the window. 

이 알고리즘을보고 나는, 각 LBP의 특징 벡터가 num_cels * 256 크기있을 것이라는 점을 결론 지을 수 있습니다

위키 백과는 basic LBP 작품이 방법을 설명합니다. 각 셀에는 256 개의 가능한 값 (0 ~ 255)이 있으므로 특성 벡터 크기가 크게 다를 수 있습니다.

그러나 일부 LBP 구현을 보면 VLFEAT_LBP은 특성 벡터 대신 매트릭스를 반환합니다. this implementation에서 LBP는 (확실하지 않은) 모든 셀의 모든 히스토그램의 합계라고 생각되는 256 특징 벡터로 반환됩니다. 내가 알고 싶은 것은 : 고전적인 LBP 설명과 MATLAB 소스 코드입니다. 감사.

+0

Canonical = [Ojala, et al.] (http://www.cse.oulu.fi/CMV/Downloads/LBPMatlab). – chappjc

+0

@chappjc 정보를 제공해 주셔서 감사합니다. 내가 소스 코드에서 본 것은 위키피디아 (6 단계)의 정보가 사실이 아니라는 것입니다. LBP에 대한 결과 이미지는 각 픽셀에서 이웃 픽셀에 따라 픽셀이 어떻게 작동하는지 나타내는 8 비트 2 진수입니다. 십진수로 변환 된 이진수는 최대 값 255와 최소값 0을 가질 수 있습니다. 각 픽셀이 이렇게 표시되면 256 개의 빈을 가진 막대 그래프가 구성됩니다. 각 셀에서 히스토그램의 연결은 수행되지 않습니다. 내가 맞습니까? – mad

답변

2
% 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('fig.jpg'); 
% 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);