问题
I'm confused with matlab "extractHOGFeature" function. I have an depth image (370x89). I want to calculate HOG on single point in an image. When I give the point[i,j] sometime it returns empty vector(0x36) and when I swap the points[i,j] to [j,i] the function return a non empty vector(1x36). Additionally I ran the function in the loop for every pixel[i,j],[j,i] and whole image separately and count the non-empty HOG vector and surprisingly I got different numbers. Let me explain in the example below.
with coordinates [i,j].
count=0;
mx=imread('abc_gray.png');
for i=1:size(mx,1)
for j=1:size(mx,2)
XY=[i,j];
hog=extractHOGFeatures(double(mx),XY);
if ~ isempty(hog)
count=count+1;
end
end
end
**Total number of non-empty vector: 5994**
with coordinates [j,i]
count=0;
mx=imread('abc_gray.png');
for i=1:size(mx,1)
for j=1:size(mx,2)
XY=[j,i];
hog=extractHOGFeatures(double(mx),XY);
if ~ isempty(hog)
count=count+1;
end
end
end
**Total number of non-empty vector: 26270**
which one is the right one?
回答1:
The extractHOGFeatures
function accepts x,y
coordinates or column, row coordinates. This means that the second version of the for
loop is the correct one. You are getting empty vectors sometimes because the coordinates you are specifying are going out of bounds in the image. This is happening because the rows and columns are flipped so there is a potential to go beyond the dimensions of the rows or columns. In addition, given your logic you technically should have 370 x 89 = 32930
HOG descriptors - one for each point. However, you have to remember that we concentrate on a window surrounding each point. If the window goes out of bounds given the point, then the HOG descriptor cannot be computed. This is why there is less than 32930 HOG descriptors to compute.
Also, running extractHOGFeatures
on the entire image and comparing this to individual points will definitely give you different sizes. What's happening is that for the entire image, there is a block-stride, meaning that there will be overlap between cells in the image so your dimensionality of the HOG feature vector will be larger than if you were to compute the HOG descriptor of each point separately.
来源:https://stackoverflow.com/questions/46594075/computing-hog-feature-on-a-single-point-using-matlab-extracthogfeature-functio