Checking Image Overlap with Mathematica – Part 3

Written by on January 16, 2017 in Image Processing, Mathematica, Programming with 0 Comments

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):

Sample Images

Sample Images

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

Image Histogram

Image Histogram

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:

Histograms

Histograms

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:

Image Levels

Image 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:

Matrix of Image Levels

Matrix of Image Levels

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.

Image Similarity

Image Similarity

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

Similarity Values

Similarity 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.

Image Distance

Image Distance

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.

Tags: , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top