diff --git a/pipi/Makefile.am b/pipi/Makefile.am
index 3aa0775..82040fa 100644
--- a/pipi/Makefile.am
+++ b/pipi/Makefile.am
@@ -25,6 +25,7 @@ libpipi_la_SOURCES = \
 	codec.c \
 	resize.c \
 	dither.c \
+	measure.c \
 	test.c \
 	$(codec_sources) \
 	filter/blur.c \
diff --git a/pipi/measure.c b/pipi/measure.c
new file mode 100644
index 0000000..c094e64
--- /dev/null
+++ b/pipi/measure.c
@@ -0,0 +1,62 @@
+/*
+ *  libpipi       Proper image processing implementation library
+ *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
+ *                All Rights Reserved
+ *
+ *  $Id$
+ *
+ *  This library is free software. It comes without any warranty, to
+ *  the extent permitted by applicable law. You can redistribute it
+ *  and/or modify it under the terms of the Do What The Fuck You Want
+ *  To Public License, Version 2, as published by Sam Hocevar. See
+ *  http://sam.zoy.org/wtfpl/COPYING for more details.
+ */
+
+/*
+ * measure.c: distance functions
+ */
+
+#include "config.h"
+#include "common.h"
+
+#include <math.h>
+
+#include "pipi.h"
+#include "pipi_internals.h"
+
+double pipi_measure_rmsd(pipi_image_t *i1, pipi_image_t *i2)
+{
+    pipi_format_t f1, f2;
+    double ret = 0.0;
+    float *p1, *p2;
+    int x, y, w, h;
+
+    w = i1->w < i2->w ? i1->w : i2->w;
+    h = i1->h < i2->h ? i1->h : i2->h;
+
+    f1 = i1->last_modified;
+    f2 = i2->last_modified;
+
+    pipi_getpixels(i1, PIPI_PIXELS_Y_F);
+    pipi_getpixels(i2, PIPI_PIXELS_Y_F);
+
+    p1 = (float *)i1->p[PIPI_PIXELS_Y_F].pixels;
+    p2 = (float *)i2->p[PIPI_PIXELS_Y_F].pixels;
+
+    for(y = 0; y < h; y++)
+        for(x = 0; x < w; x++)
+        {
+            float a = p1[y * i1->w + x];
+            float b = p2[y * i2->w + x];
+            ret += (a - b) * (a - b);
+        }
+
+    /* TODO: free pixels if they were allocated */
+
+    /* Restore original image formats */
+    i1->last_modified = f1;
+    i2->last_modified = f2;
+
+    return sqrt(ret / (w * h));
+}
+
diff --git a/pipi/pipi.h b/pipi/pipi.h
index 8f23c7e..67a33ea 100644
--- a/pipi/pipi.h
+++ b/pipi/pipi.h
@@ -59,6 +59,8 @@ extern void pipi_save(pipi_image_t *, const char *);
 
 extern pipi_pixels_t *pipi_getpixels(pipi_image_t *, pipi_format_t);
 
+extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *);
+
 extern pipi_image_t *pipi_resize(pipi_image_t *, int, int);
 
 extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);