extractLBPFeatures

extractLBPFeatures

extractLBPFeatures

Extract local binary pattern (LBP) features

Syntax

  • features = extractLBPFeatures(I)
  • features = extractLBPFeatures(I,Name,Value)
    example

Description

features = extractLBPFeatures(I) returns extracted uniform local binary pattern (LBP) from a grayscale image. The LBP features encode local texture information.

example

features = extractLBPFeatures(I,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

Code Generation Support:
Supports code generation: Yes
Generates platform-dependent library: No
Supports MATLAB® Function block: Yes
Code Generation Support, Usage Notes, and Limitations

Examples

collapse all

Using LBP Features to Differentiate Images by Texture

Read images that contain different textures.

brickWall = imread('bricks.jpg');
rotatedBrickWall = imread('bricksRotated.jpg');
carpet = imread('carpet.jpg');

Display the images.

figure
imshow(brickWall)
title('Bricks')

figure
imshow(rotatedBrickWall)
title(‘Rotated Bricks’)

figure
imshow(carpet)
title(‘Carpet’)

Extract LBP features from the images to encode their texture information.

lbpBricks1 = extractLBPFeatures(brickWall,'Upright',false);
lbpBricks2 = extractLBPFeatures(rotatedBrickWall,'Upright',false);
lbpCarpet = extractLBPFeatures(carpet,'Upright',false);

Gauge(估计) the similarity between the LBP features by computing the squared error between them.

brickVsBrick = (lbpBricks1 - lbpBricks2).^2;
brickVsCarpet = (lbpBricks1 - lbpCarpet).^2;

Visualize the squared error to compare bricks versus bricks and bricks versus carpet. The squared error is smaller when images have similar texture.

figure
bar([brickVsBrick; brickVsCarpet]','grouped')
title('Squared Error of LBP Histograms')
xlabel('LBP Histogram Bins')
legend('Bricks vs Rotated Bricks','Bricks vs Carpet')

Apply L1 Normalization to LBP Features

Read in a sample image and convert it to grayscale.

I = imread('gantrycrane.png');
I = rgb2gray(I);

Extract unnormalized LBP features so that you can apply a custom normalization.

lbpFeatures = extractLBPFeatures(I,'CellSize',[32 32],'Normalization','None');

Reshape the LBP features into a number of neighbors -by- number of cells array to access histograms for each individual cell.

numNeighbors = 8;
numBins = numNeighbors*(numNeighbors-1)+3;
lbpCellHists = reshape(lbpFeatures,numBins,[]);

Normalize each LBP cell histogram using L1 norm.

lbpCellHists = bsxfun(@rdivide,lbpCellHists,sum(lbpCellHists));

Reshape the LBP features vector back to 1-by- N feature vector.

lbpFeatures = reshape(lbpCellHists,1,[]);

Input Arguments

collapse all

I — Input imageM-by-N 2-D grayscale image

Input image, specified as an M-by-N 2-D grayscale image that is real, and non-sparse.

Data Types: logical | single | double | int16 | uint8 | uint16

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'NumNeighbors',8

Algorithm Parameters
The LBP algorithm parameters control how local binary patterns are computed for each pixel in the input image.

'NumNeighbors' — Number of neighbors8 (default) | positive integer

Number of neighbors used to compute the LBP for each pixel in the input image, specified as the comma-separated pair consisting of 'NumNeighbors' and a positive integer. The set of neighbors is selected from a circularly symmetric pattern around each pixel. Increase the number of neighbors to encode greater detail around each pixel. Typical values range from 4 to 24.

'Radius' — Radius of circular pattern to select neighbors1 (default) | positive integer

Radius of circular pattern used to select neighbors for each pixel in the input image, specified as the comma-separated pair consisting of 'Radius' and a positive integer. To capture detail over a larger spatial scale, increase the radius. Typical values range from 1 to 5.

'Upright' — Rotation invariance flagtrue | logical scalar

Rotation invariance flag, specified as the comma-separated pair consisting of 'Upright' and a logical scalar. When you set this property to true, the LBP features do not encode rotation information. Set 'Upright' to false when rotationally invariant features are required.

'Interpolation' — Interpolation method'Linear' (default) | 'Nearest'

Interpolation method used to compute pixel neighbors, specified as the comma-separated pair consisting of 'Interpolation' and the string 'Linear' or 'Nearest'. Use 'Nearest' for faster computation, but with less accuracy.

Histogram Parameters
The histogram parameters determine how the distribution of binary patterns is aggregated over the image to produce the output features.

'CellSize' — Cell sizesize(I) (default) | 2-element vector

Cell size, specified as the comma-separated pair consisting of 'CellSize' and a 2-element vector. The number of cells is calculated as floor(size(I)/CellSize.

'Normalization' — Type of normalization'L2' (default) | 'None'

Type of normalization applied to each LBP cell histogram, specified as the comma-separated pair consisting of 'Normalization' and the string 'L2' or 'None'. To apply a custom normalization method as a post-processing step, set this value to 'None'.

Output Arguments

collapse all

features — LBP feature vector1-by-N vector

LBP feature vector, returned as a 1-by-N vector of length N representing the number of features. LBP features encode local texture information, which you can use for tasks such as classification, detection, and recognition. The function partitions the input image into non-overlapping cells. To collect information over larger regions, select larger cell sizes . However, when you increase the cell size, you lose local detail. N, depends on the number of cells in the image, numCells, the number of neighbors, P, and the Upright parameter.

The number of cells is calculated as:

numCells = prod(floor(size(I)/CellSize))

The figure shows an image with nine cell histograms. Each histogram describes an LBP feature.

The size of the histogram in each cell is [1,B], where B is the number of bins in the histogram. The number of bins depends on the Upright property and the number of neighbors, P.

Upright Number of Bins
true numCells x (P x P–1) + 3)
false numCells x (P + 2)

The overall LBP feature length, N, depends on the number of cells and the number of bins, B:

N = numCells x B

References

[1] Ojala, T., M. Pietikainen, and T. Maenpaa. "Multiresolution Gray Scale and Rotation Invariant Texture Classification With Local Binary Patterns." IEEE Transactions on Pattern Analysis and Machine Intelligence. Vol. 24, Issue 7, July 2002, pp. 971-987.

Introduced in R2015b
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值