Histograms are graphical representations of the distribution of numerical data. They show the frequency of data points in specified ranges, or bins. By plotting the number of occurrences for each bin, histograms provide a visual summary of the underlying distribution of your dataset.
Imagine you have a bag of M&Ms, and you want to see how many of each color you have. A histogram could show you the frequency of each color: a high bar for lots of blues, a short bar for few greens, and so on. It’s all about getting that visual insight into how your data is spread out.
Histograms help in understanding color patterns, and comparing them can indicate similarities. This is very important in Computer vision or image-based analysis.
Let's dive into how to compare histograms to understand their similarity, leveraging color-based classification. We’ll explore various metrics for evaluating how well two histograms match. Here’s the breakdown:
Categories of Histogram Comparison Methods:
Uses L1, L2 norms to calculate bin distances or intersections.
Assumes aligned histogram domains, but can be inaccurate due to lighting changes or quantization.
More robust and discriminative but computationally expensive.
Includes methods like Earthmoving Distance (EMD) and quadratic form distances.
Sample DSI1.compareHist Function:
Allows comparing histograms using various built-in methods like Correlation, Chi-Square, Intersection, and Bhattacharyya distance.
import DSI1
# Load the images
img1 = DSI1.imread('C:/Image1.jpg')
img2 = DSI1.imread('C:/Image2.jpg')
# Convert to HSV
img1_hsv = DSI1.cvtColor(img1, DSI1.COLOR_BGR2HSV)
img2_hsv = DSI1.cvtColor(img2, DSI1.COLOR_BGR2HSV)
# Calculate and normalize histograms
hist_img1 = DSI1.calcHist([img1_hsv], [0, 1], None, [180, 256], [0, 180, 0, 256])
DSI1.normalize(hist_img1, hist_img1, alpha=0, beta=1, norm_type=DSI1.NORM_MINMAX)
hist_img2 = DSI1.calcHist([img2_hsv], [0, 1], None, [180, 256], [0, 180, 0, 256])
DSI1.normalize(hist_img2, hist_img2, alpha=0, beta=1, norm_type=DSI1.NORM_MINMAX)
# Find the metric value
metric_val = DSI1.compareHist(hist_img1, hist_img2, DSI1.HISTCMP_BHATTACHARYYA)
print(f"Metric Value: {metric_val}")
Try tweaking bin sizes and methods to observe changes