Menu

HOG setup and calculation on whole image.

Anonymous
2016-06-08
2016-06-14
  • Anonymous

    Anonymous - 2016-06-08

    I am very new to OpenIMAJ and I am trying to calculate HOG over an image/patch level. Here is how I am doing it:

    FImage image = ImageUtilities.readF(new File("image.png"));
    FlexibleHOGStrategy strategy = new FlexibleHOGStrategy(8, 8, 2);
    HOG hog = new HOG(32, true, FImageGradients.Mode.Unsigned,  strategy);
    hog.analyseImage(image);
    org.openimaj.math.geometry.shape.Rectangle roi = new org.openimaj.math.geometry.shape.Rectangle(0, 0, image.getWidth(), image.getHeight());
    Histogram histogram = hog.getFeatureVector(r);
    

    Two questions:

    1) Can anyone help me with understanding FlexibleHOGStrategy setup? I think I am confused here. Does '8' mean number of pixels? And '2' the number of pixels in overlap? See attached screenshot showing 2 cells (green and blue) and their corresponding overlap.
    2) In line HOG hog = new HOG(32, true, FImageGradients.Mode.Unsigned, strategy); I explicitly ask for feature vector of size 32. Why the histogram in line Histogram histogram = hog.getFeatureVector(r); return a vector of different size, regardless of image size?

    Basically I want to calculate HOG features across the whole image/patch and return me a feature vector of 32 bins. How can I do that?

     
  • Jonathon Hare

    Jonathon Hare - 2016-06-14

    Hi, I've just improved the javadoc documentation of FlexibleHOGStrategy as it was rather misleading. In summary:

    new FlexibleHOGStrategy(8, 8, 2): for any given window (which may cover an entire image), this will split the window into 8x8 non overlapping cells. Obviously the cells might not be square (depends on window shape), and the size in pixels will be dependent on the window size (i.e. cells will be 1/8th of the width and height respectively). From these cells, HOGs are aggregated in 2x2 square blocks, which overlap by 1 cell (there are alternate constructors that allow rectangular blocks and different overlaps).

    new HOG(32, true, FImageGradients.Mode.Unsigned, strategy): 32 is the number of orientation bins. The length of the feature will be constant for any given image (using the FlexibleHOGStrategy), and will be equal to ((number of orientation bins) * (number of blocks) * (number of cells per block)). More concretely, each cell has a 32 bin histogram, and these are aggregrated into multiple blocks, which are then aggregated into the final feature.

    If you really just want a simple 32-bin orientation histogram of an entire image (technically not a HOG descriptor, but rather just a simple gradient histogram), then you can just construct use new FlexibleHOGStrategy(1, 1, 0) which would mean that you have 1 cell (and thus 1 block). Alternatively (for less lines of code), just use the GradientOrientationHistogramExtractor class directly.

     

Anonymous
Anonymous

Add attachments
Cancel