This is the third and the last in the series of articles on checking image overlap using Mathematica.

Let us take a quick look at the images that we are using as samples (**image1** and **image3** in the first row, **image3** and **image4** in the second row):

The first technique we will consider today is the use of color histograms. The following image shows the histogram of **image1**.

We intuitively expect that if two images are similar (this happens when there is significant overlap), their histograms will also be similar. For convenience, here are the histograms of all 4 images we are evaluating:

As you can see, there is a lot of similarity between the histograms of images 1 to 3, whereas **image4** is noticeably different.

Instead of visual analysis, is there any other way to compute this similarity? The ImageLevels function allows us to get the histogram data to any level of granularity. Here is what we get for **image1** using 10 levels:

OK, how do we use this? We first convert this into a matrix without the level designator. Here is a simple function to do that and the corresponding output for **image1**:

Similarity between two images now reduces to the similarity between two matrices. I wrote the following function to compute the similarity between two images. what I do here is to compute the ContraharmonicMean of the two histogram matrices, take the EuclideanDistance between the two and take its reciprocal. Finally I scale the value up so that the fraction is not too small.

When we apply this function to the different image pairs, we get the following values:

You can see that the value is 2-3 times higher when there is significant overlap, compared to when there is little or no overlap. Of course, we have to be careful when we use this approach because it is more like an an *educated guess*.

The last function we will consider is ImageDistance. This function computes the Euclidean distance (by default) between two images.

When applied to our image pairs, we see that the distance between dissimilar images **image1** and **image4** is much higher than that between **image1** and **image2** or **image1** and **image3**. This roughly points to the degree of overlap between the image pairs.

This concludes my study of different techniques to determine the degree of overlap between two images. Hope you found the discussion useful.

## Recent Comments