1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
   | gfloat distance_hausdorff(GdkPixbuf *p1, GdkPixbuf *p2)
{
  gint i, j;
  gint x1, y1, x2, y2;
  gint l, h, n;
  guchar *pixels1, *pixels2;
  gfloat d, temp;
  gfloat resultat1, resultat2;
 
  l = gdk_pixbuf_get_width(p1);
  h = gdk_pixbuf_get_height(p1);
  n = gdk_pixbuf_get_n_channels(p1);  
 
  pixels1 = gdk_pixbuf_get_pixels(p1);
  pixels2 = gdk_pixbuf_get_pixels(p2);
 
 
  /* Calcul de la distance entre p1 et p2 */
 
  resultat1 = 0;
  for(x1 = 0; x1 < l; x1++)
    for(y1 = 0; y1 < h; y1++)
      {
    temp =  sqrt(92*92+112*112);
    i = (y1*l+x1)*n;
    for(x2 =0; x2 < l; x2++)
      for(y2 = 0; y2 < h; y2++)
        {
          j = (y2*l+x2)*n;
          if(pixels1[i] == pixels2[j])
        {
          d = dist(x1, y1, x2, y2);
          if(d < temp)
            temp = d;
        }
        }
    resultat1 += temp;
      }
 
  /* Moyenne */
 
  resultat1 = resultat1/(l*h); 
 
 
 /* Calcul de la distance entre p2 et p1 */
 
  resultat2 = 0;
  for(x2 = 0; x2 < l; x2++)
    for(y2 = 0; y2 < h; y2++)
      {
    temp =  sqrt(92*92+112*112);
    i = (y2*l+x2)*n;
    for(x1 =0; x1 < l; x1++)
      for(y1 = 0; y1 < h; y1++)
        {
          j = (y1*l+x1)*n;
          if(pixels2[i] == pixels1[j])
        {
          d = dist(x1, y1, x2, y2);
          if(d < temp)
            temp = d;
        }
        }
    resultat2 += temp;
      }
 
  /* Moyenne */
 
  resultat2 = resultat2/(l*h); 
 
  /* On retourne max(resultat1, resultat2) */
 
  return (resultat1 > resultat2) ? resultat1 : resultat2;
} | 
Partager