Customizing HOG Feature Visualization with skimage
Following the same procedure, in this example we will compute HOG features for the coffee image, which is another built-in image in skimage using hog
function from skimage. Following are the improvements made:
- Added a title to the figure for better context.
- Added annotations to the subplots for clarity.
- Used
multichannel=True
to ensure compatibility with color images. - Removed the unnecessary channel axis specification.
- Improved layout and spacing for better aesthetics.
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, exposure
image = data.coffee()
# Compute HOG features
fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True, multichannel=True)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8,4), sharex=True, sharey=True)
fig.suptitle('Coffee Cup Image with Histogram of Oriented Gradients (HOG)', fontsize=14, fontweight='bold')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Original Image')
ax1.axis('off')
# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))
# HOG Features
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('HOG Features')
ax2.axis('off')
plt.tight_layout()
plt.subplots_adjust(top=0.85) # Adjust the layout to accommodate the title
plt.show()
Output:
HOG Feature Visualization in Python Using skimage
Object detection is a fundamental task in computer vision, where the goal is to identify and locate objects within images or videos. However, this task can be challenging due to the complexity of real-world images, which often contain varying lighting conditions, occlusions, and cluttered backgrounds. Traditional approaches to object detection rely on handcrafted features, which can be time-consuming and may not generalize well to new scenarios. One popular method for feature extraction is the Histogram of Oriented Gradients (HOG) technique.
In this article, we will understand and implement examples of visualizing HOG feature arrays using skimage.
Table of Content
- Understanding HOG Features
- Advantages of HOG Feature
- Visualizing HOG Features with Python and skimage
- Customizing HOG Feature Visualization with skimage