Search code examples
image-processingsimilarity

How to measure similarity of two images


I have a program where a user draws an image by placing shapes (square, circle, triangle, rectangle) on a 5x5 grid where corner of a shape is in a grid cell and the circle in one grid cell.

I want to use that image to generate similar images. I have thought of using something like string edit distance where I replace a shape by one similar to it but need to have some way of defining which shapes are similar and by what value.

Can anyone suggest a method or algorithm that can be used to measure the similarity of the images after the whole image is generated and one to measure similarity of individual shapes? I want to eventually be able to say that given an image, I can have a similar image if the edit distance of the two images is less than some value x. I need an algorithm and supporting info that can help me come to this value.


Solution

  • I have to admit that I might not have 100% understood your question.

    However, are you looking for a similarity measure based on some structure parameters of your image, or based on the overall shape / intensity distribution of the final image?

    Is the final image an ordinary 'raster' image, i.e. pixel array with given intensity in each pixel? If so, can a simple cross-correlation coefficient do what you need? You might need to pre-process the two image before applying the cross-correlation (like edge-finding filters etc.)

    (It's normalized [0,1] with one being an exact image intensity match.)

    Edit: Following your comments below, I've now added an example. (Computed in DigitalMicrograph) I created 4 simple images ~140x140 pixels in size, and then computed the cross-correlation (CC) images of the according pairs. The CC images are arranged in the matrix and shown in temperature colour scheme for better display. The value in each CC images refers to the maximum-value in that pixel, which is the CC efficient. It should be 1 for a perfect match and 0 for a perfect "anti-match". Because of numerical rounding issues, the "auto-correlation" of an image to itself is not exactly 1 in this example.

    However, I'm still not sure if this really helps you and answers your question. The CC clearly defines a "similarity" of two images, but the exact value will depend on how many pixels you have in your image, how they are rotated with each other, and what the exact values of the pixels are. (I've used 0 for black and 1 for white). It also requires the two images to be compared to be of same pixel-size.

    enter image description here