# Comparison/Difference between two distinct plots

I am making a project where I can identify leaves by taking a picture of them and a database. I will use their widths to determine their shape. So, I worked across the stem of the leaf each width and plotted them onto the following graphs.

To compare two graphs, I take the minimum of two functions:

1. The sum of the absolute difference between two graphs for every X-axis point

2. Reverse one graph, and then run another sum of absolute difference between the reversed and the other graph. This is in case if one of the two leaves is measured in an opposite direction from the other one.

i.e. min( sum(abs(a-b)), sum(abs(a’-b)), where n’ is the reverse plot of n (In case a plot is reversed).

So, the problem is, the difference between two very similar leaves is actually greater than two very distinct leaves.

(On top) I have three graphs, two of which are similar-pos,pos2 (which should return a smaller difference), both of which are the acer ginnala leaf and another is different-neg, the betula alleghaniensis (which should return a greater difference than the "similar"):

However, this is not the case. On the 2nd layer, the two graphs are very distinct. (one is acer, other is betula). However, running the above algorithm, the sums are 70648 and 27362, returning a result of 27362.

On the last layer, when two very similar graphs are compared, (both acer) they return a much higher difference, with 40084 (normal) and 85664 (reversed), and returns the minimum of 40084, which is a higher difference than the first comparison.

I’ve tried standard deviation of the differences, squaring differences, Intersection Correlation, but had no luck. So, since the current measurement metric doesn’t work on this, what is a concise, straightforward, and better way to measure the difference between two graphs?

• Welcome to DSP.SE! What do you mean by "the difference between two graphs" ? Clearly simple subtraction is not right for you, and reversing also seems an acceptable modification. Why? What is an unacceptable modification? Otherwise all graphs are equal (if any modification is acceptable)!
– Peter K.
Sep 28, 2015 at 15:56
• What is the rationale behind allowing plot reversal ? There is something you don't tell us. More generally, like @PeterK. asked, what are similar plots for you ?
– user7657
Sep 28, 2015 at 16:41
• The graphs are from a leaf identification project I am doing, and they represent the widths of the leaf. (i.e I plotted the widths perpendicular to the stem from the top of the stem to the bottom). So, the plots are similar if, for example, both leaves' plots are a parabola, or, for the pos and pos2 (which is from acer ginnala), they have to both have a spike around the right side of the plot. Sep 28, 2015 at 22:43
• Also, the reason to reverse the plots is because maybe one leaf was measured from the top to bottom of the stem, and another was measured from bottom to top. So the reversal is in case we accidentally measured the leaves in the wrong direction. Sep 28, 2015 at 22:45

One way to compare similarly-shaped data that is translated in time is to look at the correlation between them.

If I do this in scilab:

ddata = diff(data',1,'c');

XC = xcorr(ddata(1,:),ddata(2,:));
CC1 = xcorr(ddata(1,:),ddata(1,:));
CC2 = xcorr(ddata(2,:),ddata(2,:));

den = sqrt(max(CC1)*max(CC2))

clf
plot(XC/den);
plot(CC1/max(CC1),'r')
plot(CC2/max(CC2),'m')

disp(max(XC)/den)


then I get this:

where the blue plot is the (normalized) cross-correlation of the time-differenced data and the red and magenta plots are the (normalized) auto-correlation of each individual time series.

The result is that the "correlation" between them is 0.8416782.

• Thanks for the cross-correlation tip! So just to clarify, is cross-correlation just a regular correlation, but also dragged across the x-axis so that we can re-match some shifted features and find the best possible match? Sep 28, 2015 at 23:25
• Effectively, yes.
– Peter K.
Sep 29, 2015 at 2:49