I put the size of pixels_per_cell 9x9 for 9 gradations. The image size is 126x126. Pictures are obtained norms. But if I get a feature vector, it turns out nonsense: 17424 features. Where did such a large number come from !? If you count the number of zones in the picture, they are 14x14, as it should be. Moreover, if I change the block size (cells_per_block), then the number of features decreases. Although, logically, should remain unchanged. 17424 features are obtained for a block of 2x2

hog in scikit-learn.

Hog


Sample image:

Sample image

HOG example:

enter image description here

{'cell_size': [14, 14], 'block_size': [2, 2], 'n_levels': 9, 'block_norm': u'L2'}

len(hog) == 900

  • @stackflow yes, it is - hedgehogues
  • one
    Can I see sample code with an example image? - sanmai
  • By what logic should the number of features decrease when the block size decreases? Complete the question. - sanmai

1 answer 1

 import numpy as np from skimage.feature import hog im = np.random.normal(0, 1.0, (126, 126)) hf = hog(im, orientations=9, pixels_per_cell=(9,9), cells_per_block=(2,2)) print(hf.shape) 

My code gives (6084,) , which is correct.

A common feature vector is a set of vector features for each block. For each block (block), features are a set of histograms for all cells (cells) of a given block (block).

  • The number of elements (orientations) in the histogram of each cell: 9.
  • The number of cells in the block (with cells_per_block=(2,2) ): 2 * 2 = 4.
  • That is, the number of features of one block: 9*2*2=36 .

Now, about the number of blocks. The main thing: the blocks intersect . That is, blocks are obtained by shifting by one cell , not by block size. Thus, the number of blocks, for example, horizontally: всего_ячеек - размер_блока_в_ячейках + 1 . The total number of blocks: (126/9) - 2 + 1 = 13 .

As a result, the total number of features num_blocks количество_блоков * количество_фич_на_блок : 13 * 13 *36 = 6084

The nature of the appearance of the number of features 17424 = 2*2*2*2*3*3*11*11 for the image of this size (126, 126) I do not really understand. An image of the size (207, 207) with other constant parameters, gives just such a number of features.

Just in case:

 python --version Python 3.6.2 :: Anaconda custom (64-bit) python -c "import skimage; print(skimage.__version__)" 0.13.0