source: libpipi/trunk/pipi/analysis/measure.c @ 3342

Last change on this file since 3342 was 3342, checked in by Sam Hocevar, 12 years ago

Change _C pixel format suffixes into _U8 for more clarity.

File size: 1.6 KB
Line 
1/*
2 *  libpipi       Pathetic image processing interface library
3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * measure.c: distance functions
17 */
18
19#include "config.h"
20
21#include <math.h>
22
23#include "pipi.h"
24#include "pipi_internals.h"
25
26double pipi_measure_rmsd(pipi_image_t *i1, pipi_image_t *i2)
27{
28    return sqrt(pipi_measure_msd(i1, i2));
29}
30
31double pipi_measure_msd(pipi_image_t *i1, pipi_image_t *i2)
32{
33    pipi_format_t f1, f2;
34    double ret = 0.0;
35    float *p1, *p2;
36    int x, y, w, h;
37
38    w = i1->w < i2->w ? i1->w : i2->w;
39    h = i1->h < i2->h ? i1->h : i2->h;
40
41    f1 = i1->last_modified;
42    f2 = i2->last_modified;
43
44    /* FIXME: this is not right */
45    pipi_get_pixels(i1, PIPI_PIXELS_Y_F32);
46    pipi_get_pixels(i2, PIPI_PIXELS_Y_F32);
47
48    p1 = (float *)i1->p[PIPI_PIXELS_Y_F32].pixels;
49    p2 = (float *)i2->p[PIPI_PIXELS_Y_F32].pixels;
50
51    for(y = 0; y < h; y++)
52        for(x = 0; x < w; x++)
53        {
54            float a = p1[y * i1->w + x];
55            float b = p2[y * i2->w + x];
56            ret += (a - b) * (a - b);
57        }
58
59    /* TODO: free pixels if they were allocated */
60
61    /* Restore original image formats */
62    i1->last_modified = f1;
63    i2->last_modified = f2;
64
65    return ret / (w * h);
66}
67
Note: See TracBrowser for help on using the repository browser.