I am trying to implement a procedure similar to that of MatLab whereby HOG features are extracted from an image and then plotted over either the original image, or simply standalone to estimate the shape/template of the image (see here, and below). HOG feature extraction can be easily done in R via the OpenImageR's HOG()
function, but I cannot figure out a way to recreate the plot in R. Preferably, there would be a way to overlay the features extracted onto an image via ggplot
and raster
.
HOG features overlaid on image
HOG features plotted by itself
EDIT
Here is a minimal example from R and OpenImageR
library(OpenImageR)
path = system.file("tmp_images", "1.png", package = "OpenImageR")
image = rgb_2gray(readImage(path))
image=image*255 # Convert to gray values
hog = HOG(image, cells = 9, orientations = 4)
Essentially, I load an image and extract the HOG features by slicing the 32x32 image 4 (4*4) times, and collecting 4 orientations per slice block resulting in a long unidimensional vector of 64 values (4*4 slices * 4 orientations). The trouble I am having is moving from HOG features to visualization like in the examples provided.