uniform local binary pattern
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
i need a matlab source code for "uniform local binary pattern" for textural features..
댓글 수: 1
Hola, necesitaria código de LPB para patrones uniformes e invariantes a la rotación. Si alguien me pudiera ayudar..
채택된 답변
Image Analyst
2012년 10월 6일
편집: Image Analyst
2020년 7월 30일
I don't know what "uniform" means with respect to LBP, but here is my demo for LBP, for what it's worth. It computes the LBP for each pixel with 8 different starting points. In other words, I have each of the 8 neighbors be bit 0 in turn, thus producing 8 LBP images. You can see they're all slightly different but essentially similar:
% Computes the local binary pattern of an image. Actually 8 of them with the "starting point" for the binary number at each of the 8 neighbor directions.
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 = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
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, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
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, 'BarWidth', 1, 'EdgeColor', 'none');
grid on;
title('Histogram of Original Gray Scale Image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Preallocate/instantiate array for the local binary pattern.
localBinaryPatternImage1 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage2 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage3 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage4 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage5 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage6 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage7 = zeros(size(grayImage), 'uint8');
localBinaryPatternImage8 = zeros(size(grayImage), 'uint8');
tic;
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;
% Create LBP image with the starting, LSB pixel in the upper left.
eightBitNumber = uint8(...
pixel7 * 2^7 + pixel6 * 2^6 + ...
pixel5 * 2^5 + pixel4 * 2^4 + ...
pixel3 * 2^3 + pixel2 * 2^2 + ...
pixel1 * 2 + pixel0);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage1(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the upper middle.
eightBitNumber = uint8(...
pixel6 * 2^7 + pixel5 * 2^6 + ...
pixel5 * 2^4 + pixel3 * 2^4 + ...
pixel3 * 2^2 + pixel1 * 2^2 + ...
pixel0 * 2 + pixel7);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage2(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the upper right.
eightBitNumber = uint8(...
pixel5 * 2^7 + pixel4 * 2^6 + ...
pixel3 * 2^5 + pixel2 * 2^4 + ...
pixel1 * 2^3 + pixel0 * 2^2 + ...
pixel7 * 2 + pixel6);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage3(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the center right.
eightBitNumber = uint8(...
pixel4 * 2^7 + pixel3 * 2^6 + ...
pixel2 * 2^5 + pixel1 * 2^4 + ...
pixel0 * 2^3 + pixel7 * 2^2 + ...
pixel6 * 2 + pixel5);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage4(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the lower right.
eightBitNumber = uint8(...
pixel3 * 2^7 + pixel2 * 2^6 + ...
pixel1 * 2^5 + pixel0 * 2^4 + ...
pixel7 * 2^3 + pixel6 * 2^2 + ...
pixel5 * 2 + pixel0);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage5(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the lower center.
eightBitNumber = uint8(...
pixel2 * 2^7 + pixel1 * 2^6 + ...
pixel0 * 2^5 + pixel7 * 2^4 + ...
pixel6 * 2^3 + pixel5 * 2^2 + ...
pixel4 * 2 + pixel3);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage6(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the lower left.
eightBitNumber = uint8(...
pixel1 * 2^7 + pixel0 * 2^6 + ...
pixel7 * 2^5 + pixel6 * 2^4 + ...
pixel5 * 2^3 + pixel4 * 2^2 + ...
pixel3 * 2 + pixel2);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage7(row, col) = eightBitNumber;
% Create LBP image with the starting, LSB pixel in the center left.
eightBitNumber = uint8(...
pixel0 * 2^7 + pixel7 * 2^6 + ...
pixel6 * 2^5 + pixel5 * 2^4 + ...
pixel4 * 2^3 + pixel3 * 2^2 + ...
pixel2 * 2 + pixel1);
% Or you can use the built-in function bwpack(), which is somewhat simpler but a lot slower.
% eightBitNumber = uint8(bwpack([pixel0; pixel1; pixel2; pixel3; pixel4; pixel5; pixel6; pixel7]));
localBinaryPatternImage8(row, col) = eightBitNumber;
end
end
toc;
% Outer layer of pixels will be zero because they didn't have 8 neighbors.
% So, to avoid a huge spike in the histogram at zero, replace the outer layer of pixels with the next closest layer.
localBinaryPatternImage1(1, :) = localBinaryPatternImage1(2, :);
localBinaryPatternImage1(end, :) = localBinaryPatternImage1(end-1, :);
localBinaryPatternImage1(:, 1) = localBinaryPatternImage1(:, 2);
localBinaryPatternImage1(:, end) = localBinaryPatternImage1(:, end-1);
subplot(2,2,3);
imshow(localBinaryPatternImage1, []);
title('Local Binary Pattern', 'FontSize', fontSize);
hp = impixelinfo();
hp.Units = 'normalized';
hp.Position = [0.2, 0.5, .5, .03];
subplot(2,2,4);
[pixelCounts, GLs] = imhist(uint8(localBinaryPatternImage1(2:end-1, 2:end-1)));
bar(GLs, pixelCounts, 'BarWidth', 1, 'EdgeColor', 'none');
grid on;
title('Histogram of Local Binary Pattern', 'FontSize', fontSize);
% Bring up another figure with all 8 LBP images on it, plus the average of them all.
LBPAverageImage = (double(localBinaryPatternImage1) + double(localBinaryPatternImage2) + double(localBinaryPatternImage3) + double(localBinaryPatternImage4) + double(localBinaryPatternImage5) + double(localBinaryPatternImage6) + double(localBinaryPatternImage7) + double(localBinaryPatternImage8)) / 8;
figure;
subplot(3, 3, 1);
imshow(localBinaryPatternImage1);
title('LSB at upper left', 'FontSize', fontSize);
subplot(3, 3, 2);
imshow(localBinaryPatternImage2);
title('LSB at upper center', 'FontSize', fontSize);
subplot(3, 3, 3);
imshow(localBinaryPatternImage3);
title('LSB at upper right', 'FontSize', fontSize);
subplot(3, 3, 6);
imshow(localBinaryPatternImage4);
title('LSB at center right', 'FontSize', fontSize);
subplot(3, 3, 9);
imshow(localBinaryPatternImage5);
title('LSB at lower right', 'FontSize', fontSize);
subplot(3, 3, 8);
imshow(localBinaryPatternImage6);
title('LSB at lower center', 'FontSize', fontSize);
subplot(3, 3, 7);
imshow(localBinaryPatternImage7);
title('LSB at lower left', 'FontSize', fontSize);
subplot(3, 3, 4);
imshow(localBinaryPatternImage8);
title('LSB at center left', 'FontSize', fontSize);
subplot(3, 3, 5);
imshow(LBPAverageImage, []);
title('Average of the 8', 'FontSize', fontSize, 'Color', 'r', 'FontWeight', 'bold');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
set(gcf,'name','Image Analysis Demo','numbertitle','off')
impixelinfo;
% threshold(128, 255, localBinaryPatternImage);
% Run through each gray level, displaying a map of where these gray levels occur.
% figure;
% for gl = 0 : 255
% binaryImage = localBinaryPatternImage1 == gl;
% imshow(binaryImage);
% caption = sprintf('LBP Image. Pixels with Gray Level = %d', gl);
% title(caption, 'FontSize', 12);
% drawnow;
% pause(0.04);
% end

댓글 수: 16
anum eman
2013년 12월 1일
gud job :)
hi sir great job. how can I run this programme for multiple image ? how can I remove the 0 and keep only the other in the lbp image ? thank you
Image Analyst
2014년 3월 14일
Put it into a function that you call in a loop. Use the looping code found here: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=8845#How_can_I_process_a_sequence_of_files.3F
bhagya
2014년 10월 15일
sir, your code is very simple and easy
Hi thx for code. i have questions why add brackets in imshow ? in for loop that going 3*3 mask step? finally why convert it to int? im beginner in matlab i hope answer
Image Analyst
2016년 5월 1일
Brackets in imshow() mean that it scales the intensity of the image to the max dynamic range of the display. For example if your image goes from 300 to 40,000 then using [] says that 300 shows up as black on your display and 40,000 will show up as white.
The code scans the image and for each location it gets the 8 neighbors. Converting the pattern to an integer is what the local binary pattern does. It can tell you things about texture but I never really use it so I'm not an expert on LBP.
thanks for your answer :D
Halina H
2017년 12월 14일
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
2017년 12월 14일
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
2018년 7월 24일
thanks alot sir
how can I extract LBP features of the image dataset having 2 folders one is benign( 428) and other one is malignant(227).
Image Analyst : Sir please do guide
Image Analyst
2021년 3월 29일
@RAJSHREE SRIVASTAVA, I did all my guiding via the comments. I feel the code is exceptionally well commented, especially compared to anyone else's code.
I am using MATLAB 2016B . Tried to run the code for the same problem i.e. extracting LBP features of 655 images that is stored in two folders beningn(428) and malignant(247). I have changed the code for reading the folder.
There comes an error which says that:
Error using imread>parse_inputs (line 445)
The file name or URL argument must be a character vector.
Error in imread (line 316)
[filename, fmt_s, extraArgs] = parse_inputs(varargin{:});
Error in Untitled3 (line 16)
grayImage = imread(fullFileNames);
Please help. so that I can extract LBP features of the images and then use it for classification
Evidently fullFileNames is not a character array with the full file name of the image.
On line 16 have this
fullFileNames
whos fullFileNames
and then the imread(). What does it show in the command window?
I would like to implement uniform LBP. This is the definiton given by wikipedia for uniform LBP.
A local binary pattern is called uniform if the binary pattern contains at most two bitwise transitions from 0 to 1 or vice versa when the bit pattern is traversed circularly. For example, the patterns 00000000 (0 transitions), 01110000 (2 transitions) and 11001111 (2 transitions) are uniform whereas the patterns 11001001 (4 transitions) and 01010010 (6 transitions) are not. In the computation of the LBP labels, uniform patterns are used so that there is a separate label for each uniform pattern and all the non-uniform patterns are labeled with a single label. For example, when using (8,R) neighborhood, there are a total of 256 patterns, 58 of which are uniform, which yields in 59 different labels.
I have written code for LBP but not sure how to convert it to a uniform LBP. Below is the code for LBP
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;
eightBitNumber = uint8(...
pixel7 * 2^7 + pixel6 * 2^6 + ...
pixel5 * 2^5 + pixel4 * 2^4 + ...
pixel3 * 2^3 + pixel2 * 2^2 + ...
pixel1 * 2 + pixel0);
% ...
추가 답변 (1개)
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
Image Analyst
2014년 9월 26일
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?
카테고리
도움말 센터 및 File Exchange에서 LBP - Local Binary Patterns에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
