필터 지우기
필터 지우기

How can i calculate the feature vector of local binary pattern image?

조회 수: 4 (최근 30일)
Sadia Iffat
Sadia Iffat 2017년 8월 17일
댓글: Sadia Iffat 2017년 8월 17일
I found the demo code which was published by @Image Analyst.Where local binary pattern image is calculated for the whole image. But i want to calculate it for region of interest. According to wikipedia... The LBP feature vector, in its simplest form, is created in the following manner:
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. Where the center pixel's value is greater than the neighbor's value, write "0". Otherwise, write "1". This gives an 8-digit binary number (which is usually converted to decimal for convenience).
3)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). This histogram can be seen as a 256-dimensional feature vector.
4)Optionally normalize the histogram.
5)Concatenate (normalized) histograms of all cells. This gives a feature vector for the entire window.
But according to the given code it doesn't divide the window in cells.It computes LBP for the entire image.That means it skip 1,3,4,and 5 options.How can i do it?How can do it for my region of interest?
if true
[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);
end

답변 (1개)

Image Analyst
Image Analyst 2017년 8월 17일
I see no need for step 1 and step 5. What good do they do? If you take the histogram of a bunch of 16x16 windows and then combine all the histograms, you'll get the same histogram as of the whole image, so I don't see how steps 1 and 5 are even needed, or if they were implemented how the end result would be any different that doing all "cells" at the same time (i.e. ignoring cells). Perhaps you can explain to me how it makes a difference.
If you want to get the LBP of an irregular region of interest set the pixels outside the mask to -1 or nan. Then when you scan the 8 pixel neighbors, if you encounter a -1 or nan in the pixels neighbors, just skip that pixel - don't compute the LBP for that pixel.
  댓글 수: 8
Sadia Iffat
Sadia Iffat 2017년 8월 17일
After apply LBP , i found a LBPimage.By using the statement.. A=localBinaryPatternImage(:); disp(A); I found a 1 dimensional vector such as..[54 45 56 122 34 ..]. How can i discriminiate from other images using these values..comparing 1st values with the 1st values of others,then 2nd values and so on? But it is not possible because number of values are different and it almost 20~30thousands answer please..
Sadia Iffat
Sadia Iffat 2017년 8월 17일
@Image Analyst I am waiting for your answer...

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by