[opengtl-commits] [285] add a function to compare two images

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 285
Author:   cyrille
Date:     2008-07-02 00:17:27 +0200 (Wed, 02 Jul 2008)

Log Message:
-----------
add a function to compare two images

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.cpp	2008-07-01 22:17:08 UTC (rev 284)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.cpp	2008-07-01 22:17:27 UTC (rev 285)
@@ -19,9 +19,9 @@
 
 #include "AbstractImage.h"
 
-#include <GTLCore/PixelDescription.h>
-
 #include "Debug.h"
+#include "PixelDescription.h"
+#include "Region.h"
 
 using namespace GTLCore;
 
@@ -53,3 +53,39 @@
 {
   return d->pixelSize;
 }
+
+int AbstractImage::compare( const AbstractImage* _image, const GTLCore::Region& _region) const
+{
+  // Test pixelDescription
+  if( pixelDescription() != _image->pixelDescription() )
+  {
+    std::cout << "Different pixel description : " << pixelDescription() << " != " << _image->pixelDescription() << std::endl;
+    return EXIT_FAILURE;
+  }
+  // Test pixel data
+  int _pixelSize = pixelDescription().bitsSize();
+  if( _pixelSize % 8 != 0)
+  {
+    GTL_ABORT( "Can't compare image of pixel size : " << _pixelSize << "bits.");
+  }
+  _pixelSize /= 8;
+  int errorCount = 0;
+  for(int y = 0; y < _region.height(); ++y)
+  {
+    for(int x = 0; x < _region.width(); ++x)
+    {
+      if( memcmp( data( x, y ), _image->data( x, y ), _pixelSize ) != 0)
+      {
+        if( errorCount < 100 )
+        {
+          GTL_ERROR( "Pixel (" << x << ", " << y << ") is different." );
+        } else if( errorCount == 100 )
+        {
+          GTL_ERROR( "and more...");
+        }
+        ++errorCount;
+      }
+    }
+  }
+  return errorCount;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.h	2008-07-01 22:17:08 UTC (rev 284)
+++ trunk/OpenGTL/OpenGTL/GTLCore/AbstractImage.h	2008-07-01 22:17:27 UTC (rev 285)
@@ -22,6 +22,7 @@
 
 namespace GTLCore {
   class PixelDescription;
+  class Region;
   /**
    * Base class of Images. Reimplement the virtual functions to give access to
    * your own image data.
@@ -51,7 +52,15 @@
        * to some default pixel value.
        */
       virtual char* data( int _x, int _y ) = 0;
+      virtual const char* data( int _x, int _y ) const = 0;
       const GTLCore::PixelDescription& pixelDescription() const;
+      /**
+       * Compare two images over the \param _region .
+       * 
+       * @return the number of different pixel (or -1 if pixelDescription are
+       *         different)
+       */
+      int compare( const AbstractImage* _image, const GTLCore::Region& _region) const;
     protected:
       int pixelSize() const;
     private:


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/