Come valutare la somiglianza di due istogrammi?


33

Dati due istogrammi, come possiamo valutare se sono simili o no?

È sufficiente guardare semplicemente i due istogrammi? Il semplice mapping uno a uno ha il problema che se un istogramma è leggermente diverso e leggermente spostato, non otterremo il risultato desiderato.

Eventuali suggerimenti?


2
Cosa significa "simile"? Il test chi-quadrato e il test KS, ad esempio, verificano se due istogrammi sono vicini allo stesso identico. Ma "simile" potrebbe significare "avere la stessa forma", ignorando qualsiasi differenza di posizione e / o scala. Potresti chiarire il tuo intento?
whuber

Risposte:


8

Un recente documento che potrebbe valere la pena di leggere è:

Cao, Y. Petzold, L. Limitazioni di precisione e misurazione degli errori nella simulazione stocastica di sistemi a reazione chimica, 2006.

Sebbene l'obiettivo di questo articolo sia il confronto tra algoritmi di simulazione stocastica, essenzialmente l'idea principale è come confrontare due istogrammi.

Puoi accedere al pdf dalla pagina web dell'autore.


Ciao, è un bel documento, grazie per avermi fornito il link pdf .. Avrò sicuramente questo documento ..
Mew 3.4

12
Invece di fornire un riferimento, sarebbe utile riassumere i punti principali del documento. I collegamenti muoiono, quindi in futuro la tua risposta potrebbe diventare inutile per i non abbonati di questo giornale (e la stragrande maggioranza della popolazione umana è costituita dai non abbonati).
Tim

28

Esistono molte misure di distanza tra due istogrammi. Puoi leggere una buona categorizzazione di queste misure in:

K. Meshgi e S. Ishii, "Ampliamento dell'istogramma dei colori con griglia per migliorare la precisione di tracciamento", in Proc. di MVA'15, Tokyo, Giappone, maggio 2015.

Le funzioni di distanza più popolari sono elencate qui per comodità:

  • L0 o Hellinger Distance

DL0=ih1(i)h2(i)

  • L1 , Manhattan o City Block Distance

DL1=i|h1(i)h2(i)|

  • L=2 o distanza euclidea

DL2=i(h1(i)h2(i))2

  • L or Chybyshev Distance

DL=maxi|h1(i)h2(i)|

  • Lp or Fractional Distance (part of Minkowski distance family)

DLp=(i|h1(i)h2(i)|p)1/p and 0<p<1

  • Histogram Intersection

D=1i(min(h1(i),h2(i))min(|h1(i)|,|h2(i)|)

  • Cosine Distance

DCO=1ih1(i)h2(i)

  • Canberra Distance

DCB=i|h1(i)h2(i)|min(|h1(i)|,|h2(i)|)

  • Pearson's Correlation Coefficient

DCR=i(h1(i)1n)(h2(i)1n)i(h1(i)1n)2i(h2(i)1n)2

  • Kolmogorov-Smirnov Divergance

DKS=maxi|h1(i)h2(i)|

  • Match Distance

DMA=i|h1(i)h2(i)|

  • Cramer-von Mises Distance

DCM=i(h1(i)h2(i))2

  • χ2 Statistics

Dχ2=i(h1(i)h2(i))2h1(i)+h2(i)

  • Bhattacharyya Distance

DBH=1ih1(i)h2(i) & hellinger

  • Squared Chord

DSC=i(h1(i)h2(i))2

  • Kullback-Liebler Divergance

DKL=ih1(i)logh1(i)m(i)

  • Jefferey Divergence

DJD=i(h1(i)logh1(i)m(i)+h2(i)logh2(i)m(i))

  • Earth Mover's Distance (this is the first member of Transportation distances that embed binning information A into the distance, for more information please refer to the abovementioned paper or Wikipedia entry.

DEM=minfiji,jfijAijsumi,jfij jfijh1(i),jfijh2(j),i,jfij=min(ih1(i)jh2(j)) and fij represents the flow from i to j

  • Quadratic Distance

DQU=i,jAij(h1(i)h2(j))2

  • Quadratic-Chi Distance

DQC=i,jAij(h1(i)h2(i)(cAci(h1(c)+h2(c)))m)(h1(j)h2(j)(cAcj(h1(c)+h2(c)))m) and 000

A Matlab implementation of some of these distances is available from my GitHub repository: https://github.com/meshgi/Histogram_of_Color_Advancements/tree/master/distance Also you can search guys like Yossi Rubner, Ofir Pele, Marco Cuturi and Haibin Ling for more state-of-the-art distances.

Update: Alternative explaination for the distances appears here and there in the literature, so I list them here for sake of completeness.

  • Canberra distance (another version)

DCB=i|h1(i)h2(i)||h1(i)|+|h2(i)|

  • Bray-Curtis Dissimilarity, Sorensen Distance (since the sum of histograms are equal to one, it equals to DL0)

DBC=12ih1(i)=h2(i)ih1(i)+ih2(i)

  • Jaccard Distance (i.e. intersection over union, another version)

DIOU=1imin(h1(i),h2(i))imax(h1(i),h2(i))


Welcome to our site! Thank you for this contribution.
whuber


Thanks, a list is wonderful, while it doesn't allow to create a comparison operator for histogram, e.g. to say that hist1 < hist2
Olha Pavliuk

22

The standard answer to this question is the chi-squared test. The KS test is for unbinned data, not binned data. (If you have the unbinned data, then by all means use a KS-style test, but if you only have the histogram, the KS test is not appropriate.)


You are correct that the KS test is not appropriate for histograms when it is understood as a hypothesis test about the distribution of the underlying data, but I see no reason why the KS statistic wouldn't work well as a measure of sameness of any two histograms.
whuber

An explanation of why the Kolmogorov-Smirnov test is not appropriate with binned data would be useful.
naught101

This may not be as useful in image processing as in statistical fit assessment. Often in image processing, a histogram of data is used as a descriptor for a region of an image, and the goal is for a distance between histograms to reflect the distance between image patches. Little, or possibly nothing at all, may be known about the general population statistics of the underlying image data used to get the histogram. For example, the underlying population statistics when using histograms of oriented gradients would differ considerably based on the actual content of the images.
ely

1
naught101's question was answered by Stochtastic: stats.stackexchange.com/a/108523/37373
Lapis

10

You're looking for the Kolmogorov-Smirnov test. Don't forget to divide the bar heights by the sum of all observations of each histogram.

Note that the KS-test is also reporting a difference if e.g. the means of the distributions are shifted relative to one another. If translation of the histogram along the x-axis is not meaningful in your application, you may want to subtract the mean from each histogram first.


1
Subtracting the mean changes the null distribution of the KS statistic. @David Wright raises a valid objection to the application of the KS test to histograms anyway.
whuber

7

As David's answer points out, the chi-squared test is necessary for binned data as the KS test assumes continuous distributions. Regarding why the KS test is inappropriate (naught101's comment), there has been some discussion of the issue in the applied statistics literature that is worth raising here.

An amusing exchange began with the claim (García-Berthou and Alcaraz, 2004) that one third of Nature papers contain statistical errors. However, a subsequent paper (Jeng, 2006, "Error in statistical tests of error in statistical tests" -- perhaps my all-time favorite paper title) showed that Garcia-Berthou and Alcaraz (2005) used KS tests on discrete data, leading to their reporting inaccurate p-values in their meta-study. The Jeng (2006) paper provides a nice discussion of the issue, even showing that one can modify the KS test to work for discrete data. In this specific case, the distinction boils down to the difference between a uniform distribution of the trailing digit on [0,9],

P(x)=19, (0x9)
(in the incorrect KS test) and a comb distribution of delta functions,
P(x)=110j=09δ(xj)
(in the correct, modified form). As a result of the original error, Garcia-Berthou and Alcaraz (2004) incorrectly rejected the null, while the chi-squared and modified KS test do not. In any case, the chi-squared test is the standard choice in this scenario, even if KS can be modified to work here.

-1

You can compute the cross-correlation (convolution) between both histograms. That will take into account slight traslations.


1
This is being automatically flagged as low quality, probably because it is so short. At present it is more of a comment than an answer by our standards. Can you expand on it? We can also turn it into a comment.
gung - Reinstate Monica

Since histograms are fairly unstable representations of data, and also because they do not represent probabilities using height alone (they use area), one might reasonably question the applicability, generality, or usefulness of this approach unless more specific guidance is provided.
whuber
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.