
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Haar Like Feature Detection
Haar-like feature detection is a technique used in digital image processing and object recognition. It is named after its resemblance to Haar wavelets. Paul Viola and Michael Jones adapted the idea of using Haar wavelets and developed the first real-time face detector using Haar-like features.
Haar-like features are used to identify objects or specific patterns within images. These features are characterized by their ability to consider adjacent rectangular regions at a particular location in a detection window and calculate the difference in pixel intensities between these regions. This difference is then used to classify and categorize subsections of an image.
The scikit-image library offers the haar_like_feature() function within its feature module to compute Haar-like features for a region of interest (ROI) within an integral image.
Using the skimage.feature.haar_like_feature() function
The skimage.feature.haar_like_feature function is used to compute Haar-like features for a region of interest (ROI) within an integral image. Haar-like features are often used in image classification and object detection tasks.
Syntax
Here is the syntax of this function −
skimage.feature.haar_like_feature(int_image, r, c, width, height, feature_type=None, feature_coord=None)
Parameters
The function has the following parameters −
int_image (M, N) ndarray: This is the integral image for which the Haar-like features need to be computed.
r (int): Row-coordinate of the top-left corner of the detection window (region of interest).
c (int): Column-coordinate of the top-left corner of the detection window (region of interest).
width (int): Width of the detection window (region of interest).
height (int): Height of the detection window (region of interest).
-
feature_type (str or list of str or None, optional): Specifies the type of Haar-like feature to consider. It can be one of the following −
'type-2-x': 2 rectangles varying along the x-axis.
'type-2-y': 2 rectangles varying along the y-axis.
'type-3-x': 3 rectangles varying along the x-axis.
'type-3-y': 3 rectangles varying along the y-axis.
'type-4': 4 rectangles varying along both x and y axes.
By default, all available features are extracted.
feature_coord (ndarray of list of tuples or None, optional): An array of coordinates to be extracted. This is useful when you want to recompute only a subset of features. If provided, feature_type should correspond to the feature type of each associated coordinate feature. By default, all coordinates are computed.
The function returns a NumPy array, haar_features, which is of shape (n_features,) and contains int or float values. Each value in this array is equal to the subtraction of sums of the positive and negative rectangles. The data type of haar_features depends on the data type of the int_image. It will be of type int when the data type of int_image is uint or int, and it will be of type float when the data type of int_image is float.
It's important to note that when extracting these features in parallel, the choice of the backend (i.e., multiprocessing vs. threading) can have an impact on performance. You should use multiprocessing when extracting features for all possible regions of interest (ROIs) in an image and use threading when extracting features at specific locations for a limited number of ROIs. The choice of backend depends on the specific use case and requirements for performance.
Example
This example computes the Haar-like feature of type 'type-3-x' for the entire 5x5 image using the skimage.feature.haar_like_feature() function.
import numpy as np import matplotlib.pyplot as plt from skimage.transform import integral_image from skimage.feature import haar_like_feature # Create a simple binary image (5x5) for illustration img = np.ones((5, 5), dtype=np.uint8) # Compute the integral image img_ii = integral_image(img) # Compute the Haar-like feature for the entire image feature = haar_like_feature(img_ii, 0, 0, 5, 5, 'type-3-x') # Display the original and the computed Haar-like feature fig, axes = plt.subplots(1, 2, figsize=(10, 8)) ax = axes.ravel() ax[0].imshow(img_ii) ax[0].set_title('Input integral Image') ax[0].axis('off') # Display the computed Haar-like feature ax[1].imshow(feature.reshape(1, -1), cmap='coolwarm', aspect='auto') ax[1].set_title('Haar-like Feature') ax[1].axis('off') plt.show()
Output

Additionally, the haar_like_feature() function can be used to compute the feature for some pre-computed coordinates.
Example
Here is the example, that uses the haar_like_feature_coord() and the haar_like_feature() functions to compute the Haar-lik feature for some pre-computed coordinates.
import numpy as np import matplotlib.pyplot as plt from skimage.transform import integral_image from skimage.feature import haar_like_feature, haar_like_feature_coord # Create a simple binary image (5x5) img = np.ones((5, 5), dtype=np.uint8) # Compute the integral image img_ii = integral_image(img) # Define the feature coordinates and types feature_coord, feature_type = zip( *[haar_like_feature_coord(5, 5, feat_t) for feat_t in ('type-2-x', 'type-3-x')]) # only select one feature over two feature_coord = np.concatenate([x[::2] for x in feature_coord]) feature_type = np.concatenate([x[::2] for x in feature_type]) # Compute the Haar-like feature for the specified coordinates feature = haar_like_feature(img_ii, 0, 0, 5, 5, feature_type=feature_type, feature_coord=feature_coord) # Display the original and the computed Haar-like feature fig, axes = plt.subplots(1, 2, figsize=(10, 8)) ax = axes.ravel() ax[0].imshow(img_ii) ax[0].set_title('Input integral Image') ax[0].axis('off') # Display the computed Haar-like feature ax[1].imshow(feature.reshape(1, -1), cmap='coolwarm', aspect='auto') ax[1].set_title('Haar-like Feature') ax[1].axis('off') plt.show() # Print the computed Haar-like feature print("Computed Haar-like Feature:", feature)
Output
Computed Haar-like Feature: [ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 -3 -5 -2 -4 -1 -3 -5 -2 -4 -2 -4 -2 -4 -2 -1 -3 -2 -1 -1 -1 -1 -1]
