extractHOGFeatures
Extract histogram of oriented gradients (HOG) features
Syntax
Description
returns extracted HOG features from a truecolor or grayscale input image,features
= extractHOGFeatures(I
)I
。The features are returned in a 1-by-Nvector, whereNis the HOG feature length. The returned features encode local shape information from regions within an image. You can use this information for many tasks including classification, detection, and tracking.
[
returns HOG features extracted around specified point locations. The function also returnsfeatures
,validPoints
] = extractHOGFeatures(I
,points
)validPoints
,其中包含的输入点位置的年代urrounding region is fully contained withinI
。Scale information associated with the points is ignored.
[___,
可以返回一个猪特征可视化,我们ing any of the preceding syntaxes. You can display this visualization usingvisualization
] = extractHOGFeatures(I
,___)plot
(visualization
).
[___] = extractHOGFeatures(___,
uses additional options specified by one or more Name,Value pair arguments, using any of the preceding syntaxes.Name,Value
)
Examples
Extract and Plot HOG Features
Read the image of interest.
img = imread('cameraman.tif');
Extract HOG features.
[featureVector,hogVisualization] = extractHOGFeatures(img);
Plot HOG features over the original image.
figure; imshow(img); holdon; plot(hogVisualization);
Extract HOG Features using CellSize
Read the image of interest.
I1 = imread('gantrycrane.png');
Extract HOG features.
[hog1,visualization] = extractHOGFeatures(I1,'CellSize',[32 32]);
Display the original image and the HOG features.
subplot(1,2,1); imshow(I1); subplot(1,2,2); plot(visualization);
Extract HOG Features Around Corner Points
Read in the image of interest.
I2 = imread('gantrycrane.png');
Detect and select the strongest corners in the image.
corners = detectFASTFeatures(im2gray(I2)); strongest = selectStrongest(corners,3);
Extract HOG features.
[hog2,validPoints,ptVis] = extractHOGFeatures(I2,strongest);
Display the original image with an overlay of HOG features around the strongest corners.
figure; imshow(I2); holdon; plot(ptVis,'Color','green');
Input Arguments
I
—Input image
M-by-N-by-3 truecolor image|M-by-N2-D grayscale image
Input image, specified in eitherM-by-N-by-3 truecolor orM-by-N2-D grayscale. The input image must be a real, nonsparse value. If you have tightly cropped images, you may lose shape information that the HOG function can encode. You can avoid losing this information by including an extra margin of pixels around the patch that contains background pixels.
Data Types:single
|double
|int16
|uint8
|uint16
|logical
points
—Center location point
BRISKPoints
object|cornerPoints
object|SURFPoints
object|MSERRegions
object|M-by-2 matrix of [x,y] coordinates
Center location point of a square neighborhood, specified as either aBRISKPoints
,SURFPoints
,MSERRegions
,ORBPoints
orcornerPoints
object, or anM-by-2 matrix ofMnumber of [x,y] coordinates. The function extracts descriptors from the neighborhoods that are fully contained within the image boundary. You can set the size of the neighborhood with theBlockSize
parameter. Only neighborhoods fully contained within the image are used to determine the valid output points. The function ignores scale information associated with these points.
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, whereName
is the argument name andValue
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Example:'BlockSize'
,[2 2]
sets theBlockSize
to be a 2-by-2 square block.
CellSize
—Size of HOG cell
[8 8]
(default) |2-element vector
Size of HOG cell, specified in pixels as a 2-element vector. To capture large-scale spatial information, increase the cell size. When you increase the cell size, you may lose small-scale detail.
BlockSize
—Number of cells in block
[2 2]
(default) |2-element vector
Number of cells in a block, specified as a 2-element vector. A large block size value reduces the ability to suppress local illumination changes. Because of the number of pixels in a large block, these changes may get lost with averaging. Reducing the block size helps to capture the significance of local pixels. Smaller block size can help suppress illumination changes of HOG features.
BlockOverlap
—Number of overlapping cells between adjacent blocks
ceil
(BlockSize/2)
(default)
Number of overlapping cells between adjacent blocks, specified as a 2-element vector. To ensure adequate contrast normalization, select an overlap of at least half the block size. Large overlap values can capture more information, but they produce larger feature vector size. This property applies only when you are extracting HOG features from regions and not from point locations. When you are extracting HOG features around a point location, only one block is used, and thus, no overlap occurs.
NumBins
—Number of orientation histogram bins
9
(default) |positive scalar
Number of orientation histogram bins, specified as positive scalar. To encode finer orientation details, increase the number of bins. Increasing this value increases the size of the feature vector, which requires more time to process.
UseSignedOrientation
—Selection of orientation values
false
(default) |logical scalar
Selection of orientation values, specified as a logical scalar. When you set this property totrue
, orientation values are evenly spaced in bins between -180 and 180 degrees. When you set this property tofalse
, they are evenly spaced from 0 through 180. In this case, values of theta that are less than 0 are placed into a theta + 180 value bin. Using signed orientation can help differentiate light-to-dark versus dark-to-light transitions within an image region.
Output Arguments
features
— Extracted HOG features
1-by-Nvector |P-by-Qmatrix
Extracted HOG features, returned as either a 1-by-Nvector or aP-by-Qmatrix. The features encode local shape information from regions or from point locations within an image. You can use this information for many tasks including classification, detection, and tracking.
features output |
Description |
---|---|
1-by-Nvector | HOG feature length,N, is based on the image size and the function parameter values. N= prod ([BlocksPerImage,BlockSize ,NumBins ])BlocksPerImage= floor ((size (I )./CellSize –BlockSize )./(BlockSize –BlockOverlap ) + 1) |
P-by-Qmatrix | Pis the number of valid points whose surrounding region is fully contained within the input image. You provide thepoints input value for extracting point locations.The surrounding region is calculated as: CellSize 。*BlockSize 。The feature vector length,Q, is calculated as: prod ([NumBins ,BlockSize ]). |
The figure below shows an image with six cells.
If you set theBlockSize
to [2 2
], it would make the size of each HOG block, 2-by-2 cells. The size of the cells are in pixels. You can set it with theCellSize
property.
The HOG feature vector is arranged by HOG blocks. The cell histogram, H(Cyx), is 1-by-NumBins
。
The figure below shows the HOG feature vector with a 1-by-1 cell overlap between blocks.
validPoints
— Valid points
cornerPoints
object |BRISKPoints
object |SURFPoints
object |MSERRegions
object |ORBPoints
object |M-by-2 matrix of [x,y] coordinates
Valid points associated with eachfeatures
descriptor vector output. This output can be returned as either acornerPoints
object,BRISKPoints
,SURFPoints
object,MSERRegions
object,ORBPoints
object or anM-by-2 matrix of [x,y] coordinates. The function extractsMnumber of descriptors from valid interest points in a region of size equal to [CellSize
。*BlockSize
]. The extracted descriptors are returned as the same type of object or matrix as the input. The region must be fully contained within the image.
visualization
— HOG feature visualization
object
HOG feature visualization, returned as an object. The function outputs this optional argument to visualize the extracted HOG features. You can use theplot
method with thevisualization
output. See theExtract and Plot HOG Featuresexample.
HOG features are visualized using a grid of uniformly spacedrose
plots. The cell size and the size of the image determines the grid dimensions. Each rose plot shows the distribution of gradient orientations within a HOG cell. The length of each petal of the rose plot is scaled to indicate the contribution each orientation makes within the cell histogram. The plot displays the edge directions, which are normal to the gradient directions. Viewing the plot with the edge directions allows you to better understand the shape and contours encoded by HOG. Each rose plot displays two timesNumBins
petals.
You can use the following syntax to plot the HOG features:
plot(visualization) plots the HOG features as an array of rose plots. |
plot(visualization,AX) plots HOG features into the axes AX. |
plot(___,'Color',colorValue) Specifies the color used to plot HOG features, wherecolorValue represents the color as a 1-by-3 RGB vector, a short, or a long color name, described in theColor Valuetable. |
More About
Color Value
Color Name | Short Name | RGB Triplet | Appearance |
---|---|---|---|
"red" |
"r" |
[1 0 0] |
|
"green" |
"g" |
[0 1 0] |
|
"blue" |
"b" |
[0 0 1] |
|
"cyan" |
"c" |
[0 1 1] |
|
"magenta" |
"m" |
[1 0 1] |
|
"yellow" |
"y" |
[1 1 0] |
|
"black" |
"k" |
[0 0 0] |
|
"white" |
"w" |
[1 1 1] |
|
References
[1] Dalal, N. and B. Triggs. "Histograms of Oriented Gradients for Human Detection",IEEE Computer Society Conference on Computer Vision and Pattern Recognition, Vol. 1 (June 2005), pp. 886–893.
Extended Capabilities
C/C++ Code Generation
生成C和c++代码使用MATLAB®编码器™。
Version History
Introduced in R2013b
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- 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)