[opengtl-commits] [293] * add gtlconvert to convert images using GTLImageIO => only usefull to debug GTLImageIO

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


Revision: 293
Author:   cyrille
Date:     2008-07-02 00:22:11 +0200 (Wed, 02 Jul 2008)

Log Message:
-----------
* add gtlconvert to convert images using GTLImageIO => only usefull to debug GTLImageIO
* add imagecompare which is a tool for comparing the data of two images

Added Paths:
-----------
    trunk/OpenGTL/OpenGTL/tools/
    trunk/OpenGTL/OpenGTL/tools/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/tools/convert/
    trunk/OpenGTL/OpenGTL/tools/convert/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/tools/convert/GTLConvert.cpp
    trunk/OpenGTL/OpenGTL/tools/imagecompare/
    trunk/OpenGTL/OpenGTL/tools/imagecompare/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/tools/imagecompare/ImageCompare.cpp


Added: trunk/OpenGTL/OpenGTL/tools/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/CMakeLists.txt	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/tools/CMakeLists.txt	2008-07-01 22:22:11 UTC (rev 293)
@@ -0,0 +1,2 @@
+add_subdirectory(convert)
+add_subdirectory(imagecompare)
\ No newline at end of file

Added: trunk/OpenGTL/OpenGTL/tools/convert/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/convert/CMakeLists.txt	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/tools/convert/CMakeLists.txt	2008-07-01 22:22:11 UTC (rev 293)
@@ -0,0 +1,8 @@
+include_directories( ${CMAKE_SOURCE_DIR} )
+
+set( convert_SRCS
+     GTLConvert.cpp )
+
+add_executable(gtlconvert ${convert_SRCS})
+target_link_libraries(gtlconvert GTLImageIO )
+install( TARGETS gtlconvert DESTINATION ${BIN_INSTALL_DIR} )

Added: trunk/OpenGTL/OpenGTL/tools/convert/GTLConvert.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/convert/GTLConvert.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/tools/convert/GTLConvert.cpp	2008-07-01 22:22:11 UTC (rev 293)
@@ -0,0 +1,100 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// C++ Headers
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+
+// GTLCore Headers
+#include <GTLCore/Region.h>
+
+// GTLImageIO Headers
+#include <GTLImageIO/ImageDC.h>
+#include <GTLImageIO/ImageDCRegistry.h>
+#include <GTLImageIO/Version.h>
+
+void printVersion()
+{
+  std::cout << GTLImageIO::LibraryShortName << " - " << GTLImageIO::LibraryName << " - " << GTLImageIO::LibraryVersionString << std::endl;
+  std::cout << GTLImageIO::LibraryCopyright << std::endl;
+}
+void printHelp()
+{
+  std::cout << "Usage : gtlconvert fileNameInput fileNameOutput" << std::endl;
+  std::cout << std::endl;
+  std::cout << "Options : " << std::endl;
+  std::cout << std::endl;
+  std::cout << "  -h --help               print this message" << std::endl;
+  std::cout << "  -v --version            print the version information" << std::endl;
+}
+
+#define ARG_IS(a,b) argv[ai] == GTLCore::String(a) or argv[ai] == GTLCore::String(b)
+
+int main(int argc, char** argv)
+{
+  GTLCore::String fileName = "";
+  for(int ai = 1; ai < argc; ai++)
+  {
+    if(ARG_IS("-h","--help"))
+    {
+      printHelp();
+      return EXIT_SUCCESS;
+    } else if(ARG_IS("-v","--version"))
+    {
+      printVersion();
+      return EXIT_SUCCESS;
+    } else {
+      break;
+    }
+  }
+  if( argc != 3)
+  {
+    printHelp();
+  } else {
+    GTLCore::String inputFileName = argv[1]; 
+    GTLCore::String outputFileName = argv[2];
+    const GTLImageIO::ImageDC* decoder = GTLImageIO::ImageDCRegistry::instance()->decoder( inputFileName );
+    if(not decoder )
+    {
+      std::cerr << "No decoder for " << inputFileName << std::endl;
+      return EXIT_FAILURE;
+    }
+    const GTLImageIO::ImageDC* encoder = GTLImageIO::ImageDCRegistry::instance()->encoder( outputFileName );
+    if(not decoder )
+    {
+      std::cerr << "No encoder for " << outputFileName << std::endl;
+      return EXIT_FAILURE;
+    }
+    GTLCore::String errMsg;
+    GTLCore::Region region;
+    GTLCore::AbstractImage* image = decoder->decode( inputFileName, &region, &errMsg );
+    if( not image )
+    {
+      std::cerr << "Error while decoding " << inputFileName << " : " << errMsg << std::endl;
+      return EXIT_FAILURE;
+    }
+    if(not encoder->encode( image, region, outputFileName, &errMsg ))
+    {
+      std::cerr << "Error while encoding " << outputFileName << " : " << errMsg << std::endl;
+      return EXIT_FAILURE;
+    }
+  }
+  return EXIT_SUCCESS;
+}


Property changes on: trunk/OpenGTL/OpenGTL/tools/convert/GTLConvert.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenGTL/tools/imagecompare/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/imagecompare/CMakeLists.txt	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/tools/imagecompare/CMakeLists.txt	2008-07-01 22:22:11 UTC (rev 293)
@@ -0,0 +1,10 @@
+include_directories( ${CMAKE_SOURCE_DIR} )
+
+set( ImageCompare_SRCS
+     ImageCompare.cpp )
+
+add_definitions( -DCOUMPONENT_NAME=\"\\\"ImageCompare\\\"\" )
+
+add_executable(imagecompare ${ImageCompare_SRCS})
+target_link_libraries(imagecompare GTLImageIO )
+install( TARGETS imagecompare DESTINATION ${BIN_INSTALL_DIR} )

Added: trunk/OpenGTL/OpenGTL/tools/imagecompare/ImageCompare.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/tools/imagecompare/ImageCompare.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenGTL/tools/imagecompare/ImageCompare.cpp	2008-07-01 22:22:11 UTC (rev 293)
@@ -0,0 +1,117 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// C++ Headers
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+
+// GTLCore Headers
+#include <GTLCore/AbstractImage.h>
+#include <GTLCore/Debug.h>
+#include <GTLCore/PixelDescription.h>
+#include <GTLCore/Region.h>
+
+// GTLImageIO Headers
+#include <GTLImageIO/ImageDC.h>
+#include <GTLImageIO/ImageDCRegistry.h>
+#include <GTLImageIO/Version.h>
+
+void printVersion()
+{
+  std::cout << GTLImageIO::LibraryShortName << " - " << GTLImageIO::LibraryName << " - " << GTLImageIO::LibraryVersionString << std::endl;
+  std::cout << GTLImageIO::LibraryCopyright << std::endl;
+}
+void printHelp()
+{
+  std::cout << "Usage : imagecompare file1 file2" << std::endl;
+  std::cout << std::endl;
+  std::cout << "Options : " << std::endl;
+  std::cout << std::endl;
+  std::cout << "  -h --help               print this message" << std::endl;
+  std::cout << "  -v --version            print the version information" << std::endl;
+}
+
+#define ARG_IS(a,b) argv[ai] == GTLCore::String(a) or argv[ai] == GTLCore::String(b)
+
+int main(int argc, char** argv)
+{
+  GTLCore::String fileName = "";
+  for(int ai = 1; ai < argc; ai++)
+  {
+    if(ARG_IS("-h","--help"))
+    {
+      printHelp();
+      return EXIT_SUCCESS;
+    } else if(ARG_IS("-v","--version"))
+    {
+      printVersion();
+      return EXIT_SUCCESS;
+    } else {
+      break;
+    }
+  }
+  if( argc != 3)
+  {
+    printHelp();
+  } else {
+    GTLCore::String fileName1 = argv[1]; 
+    GTLCore::String fileName2 = argv[2];
+    const GTLImageIO::ImageDC* decoder1 = GTLImageIO::ImageDCRegistry::instance()->decoder( fileName1 );
+    if(not decoder1 )
+    {
+      std::cerr << "No decoder for " << fileName1 << std::endl;
+      return EXIT_FAILURE;
+    }
+    const GTLImageIO::ImageDC* decoder2 = GTLImageIO::ImageDCRegistry::instance()->decoder( fileName2 );
+    if(not decoder2 )
+    {
+      std::cerr << "No encoder for " << fileName2 << std::endl;
+      return EXIT_FAILURE;
+    }
+    GTLCore::String errMsg;
+    GTLCore::Region region1;
+    GTLCore::AbstractImage* image1 = decoder1->decode( fileName1, &region1, &errMsg );
+    if( not image1 )
+    {
+      std::cerr << "Error while decoding " << fileName1 << " : " << errMsg << std::endl;
+      return EXIT_FAILURE;
+    }
+    GTLCore::Region region2;
+    GTLCore::AbstractImage* image2 = decoder2->decode( fileName2, &region2, &errMsg );
+    if(not image2 )
+    {
+      std::cerr << "Error while decoding " << fileName2 << " : " << errMsg << std::endl;
+      return EXIT_FAILURE;
+    }
+    // Test size
+    if( region1 != region2 )
+    {
+      std::cout << "Different image size : " << region1 << " != " << region2 << std::endl;
+      return EXIT_FAILURE;
+    }
+    int errorCount = image1->compare( image2, region1 );
+    if( errorCount != 0 )
+    {
+      std::cout << errorCount << " different pixels" << std::endl;
+      return EXIT_FAILURE;
+    }
+  }
+  return EXIT_SUCCESS;
+}


Property changes on: trunk/OpenGTL/OpenGTL/tools/imagecompare/ImageCompare.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native


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