You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.5 KiB

  1. /*
  2. * libpipi Proper image processing implementation 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. * measure.c: distance functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <math.h>
  20. #include "pipi.h"
  21. #include "pipi_internals.h"
  22. double pipi_measure_rmsd(pipi_image_t *i1, pipi_image_t *i2)
  23. {
  24. pipi_format_t f1, f2;
  25. double ret = 0.0;
  26. float *p1, *p2;
  27. int x, y, w, h;
  28. w = i1->w < i2->w ? i1->w : i2->w;
  29. h = i1->h < i2->h ? i1->h : i2->h;
  30. f1 = i1->last_modified;
  31. f2 = i2->last_modified;
  32. pipi_getpixels(i1, PIPI_PIXELS_Y_F);
  33. pipi_getpixels(i2, PIPI_PIXELS_Y_F);
  34. p1 = (float *)i1->p[PIPI_PIXELS_Y_F].pixels;
  35. p2 = (float *)i2->p[PIPI_PIXELS_Y_F].pixels;
  36. for(y = 0; y < h; y++)
  37. for(x = 0; x < w; x++)
  38. {
  39. float a = p1[y * i1->w + x];
  40. float b = p2[y * i2->w + x];
  41. ret += (a - b) * (a - b);
  42. }
  43. /* TODO: free pixels if they were allocated */
  44. /* Restore original image formats */
  45. i1->last_modified = f1;
  46. i2->last_modified = f2;
  47. return sqrt(ret / (w * h));
  48. }