PIXELBANKv8.2.1
Menu

Histogram Comparison

Implement a function to compare the similarity between two grayscale images using histogram intersection. This technique is based on the idea of representing images as histograms, which are graphical representations of the distribution of pixel intensities.

The comparison of two histograms, AA and BB, is done by calculating the intersection between them, which is a measure of the amount of overlap between the two distributions.

  1. Represent each image as a histogram with 256 bins, where each bin corresponds to a possible pixel intensity value.
  2. Calculate the minimum value between corresponding bins in the two histograms.
  3. Sum up these minimum values to obtain the histogram intersection.
H(A,B)=i=0255min(Ai,Bi)H(A,B) = \sum_{i=0}^{255} \min(A_i, B_i)

This technique is widely used in image retrieval and object recognition systems.

Example:

Input:
histogram_intersection([[0,1,2]], [[0,1,2]])
Output:
1.0
Reasoning:

Identical histograms have intersection = 1.0

Constraints:

  • Input images are 2D grayscale arrays with values in [0, 255]
  • Return the intersection value normalized by total pixels in smaller image
Editor

Test Results

0/0
Run code to see test results.