[med-svn] [mia] 03/05: Imported Upstream version 2.0.12

Gert Wollny gert-guest at moszumanska.debian.org
Wed Nov 27 13:53:33 UTC 2013


This is an automated email from the git hooks/post-receive script.

gert-guest pushed a commit to branch master
in repository mia.

commit 93ea45f0eb0d67eb812689057feb91ba6ee8df61
Author: Gert Wollny <gw.fossdev at gmail.com>
Date:   Wed Nov 27 12:40:02 2013 +0100

    Imported Upstream version 2.0.12
---
 CMakeLists.txt                                     |  36 +++-
 ChangeLog                                          |  25 +++
 addons/CMakeLists.txt                              |   4 +
 addons/dicom/CMakeLists.txt                        |   1 +
 addons/dicom/dcm2d.cc                              |   5 +
 addons/dicom/dcm2d.hh                              |   1 +
 addons/dicom/dcm3d.cc                              |  30 ++-
 addons/dicom/dicom4mia.cc                          |  14 +-
 addons/dicom/dicom4mia.hh                          |   2 +-
 {mia/2d/rgbio => addons/jpg}/CMakeLists.txt        |  32 ++--
 mia/2d/io/jpg.cc => addons/jpg/jpg-gray.cc         |   0
 mia/2d/rgbio/jpg.cc => addons/jpg/jpg-rgb.cc       |   0
 .../core/minimizer => addons/nlopt}/CMakeLists.txt |  13 +-
 {mia/core/minimizer => addons/nlopt}/nlopt.cc      |   2 +-
 {mia/core/minimizer => addons/nlopt}/nlopt.hh      |   0
 {mia/core/minimizer => addons/nlopt}/test_nlopt.cc |   2 +-
 addons/openexr/2dimgexr.cc                         |   7 +-
 addons/openexr/2dvfexr.cc                          |   8 +-
 addons/openexr/CMakeLists.txt                      |   2 +-
 {mia/2d/rgbio => addons/png}/CMakeLists.txt        |  33 ++--
 mia/2d/io/png.cc => addons/png/png-gray.cc         |   0
 mia/2d/rgbio/png.cc => addons/png/png-rgb.cc       |   0
 {mia/2d/rgbio => addons/tiff}/CMakeLists.txt       |  29 +--
 {mia/2d/io => addons/tiff}/tiff.cc                 |   0
 addons/vistaio/CMakeLists.txt                      |   1 +
 addons/vistaio/test_vista4mia.cc                   |   5 +-
 addons/vtk/CMakeLists.txt                          |   1 +
 addons/vtk/vtkimage.cc                             |   2 +-
 addons/vtk/vtkmesh.cc                              |   3 +-
 addons/vtk/vtkvf.cc                                |   5 +-
 config.h.cmake                                     |  14 ++
 mia/2d/CMakeLists.txt                              |  32 ----
 mia/2d/SegStar.cc                                  |   3 +-
 mia/2d/cost/ngf.hh                                 |   5 +-
 mia/2d/creator/circle.cc                           |   2 +-
 mia/2d/fftkernel.cc                                |   9 +-
 mia/2d/filter/aniso.cc                             |   5 +-
 mia/2d/filter/mask.cc                              |   3 +-
 mia/2d/filter/mean.cc                              |  14 +-
 mia/2d/filter/test_mlv.cc                          |   2 +-
 mia/2d/fuzzyClusterSolverCG.cc                     |   7 +
 mia/2d/io/CMakeLists.txt                           |  17 --
 mia/2d/io/bmp.cc                                   |  82 +++++---
 mia/2d/model/navier.cc                             |   5 +-
 mia/2d/model/navier.hh                             |   2 +-
 mia/2d/model/naviera.hh                            |   2 +-
 mia/2d/perfusion.cc                                |   4 +-
 mia/2d/rgbio/CMakeLists.txt                        |  11 --
 mia/2d/test_imageio.cc                             |   5 +-
 mia/2d/test_interpol.cc                            |  13 +-
 mia/2d/test_ppmatrix.cc                            |  11 +-
 mia/2d/test_rigidregister.cc                       |  58 ++----
 mia/3d/camera.cc                                   |   7 +-
 mia/3d/camera.hh                                   |   2 +-
 mia/3d/cost/ngf.hh                                 |   4 -
 mia/3d/creator/sphere.cc                           |   2 +-
 mia/3d/fifof/mlv.cc                                |   3 +-
 mia/3d/fifof/mlv.hh                                |   2 -
 mia/3d/fifof/regiongrow.cc                         |   3 +-
 mia/3d/filter/mask.cc                              |   3 +-
 mia/3d/filter/reorient.hh                          |   1 -
 mia/3d/filter/scale.cc                             |  87 +++++----
 mia/3d/filter/test_mlv.cc                          |   2 +-
 mia/3d/fullcost/taggedssd.hh                       |   2 -
 mia/3d/fuzzyClusterSolverCG.cc                     |   7 +
 mia/3d/image.cc                                    |   1 +
 mia/3d/io/analyze.cc                               |  22 ++-
 mia/3d/io/inria.cc                                 |   1 +
 mia/3d/io/vff.cc                                   |  15 +-
 mia/3d/landmark.cc                                 |   6 +-
 mia/3d/reg3d/navier.cc                             |   6 +-
 mia/3d/reg3d/naviera.cc                            |   4 +-
 mia/3d/reg3d/navierasse.cc                         |   2 +-
 mia/3d/test_3d.cc                                  |   5 +-
 mia/3d/test_imageio.cc                             |   5 +-
 mia/3d/test_ppmatrix.cc                            |  13 +-
 mia/3d/test_rigidregister.cc                       |  61 ++----
 mia/3d/transform.cc                                |   3 +-
 mia/3d/transform/test_spline.cc                    |   4 +-
 mia/core/CMakeLists.txt                            |   1 -
 mia/core/attributes.hh                             |  10 +-
 mia/core/cmdlineparser.cc                          |   8 +-
 mia/core/fftslopeclassifier.cc                     |   7 +-
 mia/core/fifofilter.cxx                            |   2 +
 mia/core/fixedwidthoutput.cc                       |   2 +-
 mia/core/handler.cxx                               |   6 +-
 mia/core/histogram.hh                              |   2 +-
 mia/core/history.cc                                |   3 +-
 mia/core/iohandler.cxx                             |  13 +-
 mia/core/minimizer/CMakeLists.txt                  |  19 --
 mia/core/minimizer/gsl.cc                          |   9 +
 mia/core/noise/gauss.cc                            |   3 +-
 mia/core/parameter.hh                              |   4 +-
 mia/core/plugin_base.cc                            |  19 ++
 mia/core/plugin_base.hh                            |  15 ++
 mia/core/slopestatistics.cc                        |  14 ++
 mia/core/spacialkernel/gauss.cc                    |   7 +-
 mia/core/splineparzenmi.cc                         |   2 +
 mia/core/splineparzenmi.hh                         |   3 +
 mia/core/test_attributes.cc                        |  14 +-
 mia/core/test_cmdlineparser.cc                     |  25 ++-
 mia/core/test_filter.cc                            |   3 +-
 mia/core/test_histogram.cc                         |  11 ++
 mia/core/test_iohandler.cc                         |   2 +-
 mia/core/test_shape.cc                             |   3 +
 mia/core/test_streamredir.cc                       |  15 +-
 mia/core/threadedmsg.cc                            |   4 +-
 mia/core/threadedmsg.hh                            |   1 -
 mia/core/waveletslopeclassifier.cc                 |   2 +
 mia/internal/autotest.hh                           |   6 +-
 mia/internal/main.hh                               |  48 ++---
 mia/internal/plugintester.hh                       |   6 +-
 mia/template/mi.hh                                 |   1 -
 mia/template/ssd.hh                                |   1 -
 src/2davgmasked.cc                                 |   7 +-
 src/2deval-transformquantity.cc                    |  10 +-
 src/2dimagefilterstack.cc                          |   6 -
 src/2dmultiimageto3d.cc                            |  81 ++++++++
 src/2dmyocard-segment.cc                           |   2 +-
 src/2dmyoica-nonrigid2.cc                          |   8 +-
 src/2dmyoperiodic-nonrigid.cc                      |  17 +-
 src/2dsegment-ahmed.cc                             |   4 +-
 src/2dseriescorr.cc                                |   2 +
 src/2dtransformation-to-strain.cc                  |   2 +-
 src/3dprealign-nonrigid.cc                         | 107 +++++++----
 src/3dsegment-ahmed.cc                             |   4 +-
 src/CMakeLists.txt                                 |   1 +
 src/fluid2d/main.cc                                |   2 +-
 src/fluid3d/sor_solver.cc                          |   3 +-
 src/fluid3d/vfluid.cc                              |   4 +
 src/raw2image.cc                                   |   8 +-
 src/raw2volume.cc                                  |   9 +-
 {addons => test}/CMakeLists.txt                    |   8 +-
 test/test_ioplugins.cc                             | 210 +++++++++++++++++++++
 test/test_minimizer.cc                             | 191 +++++++++++++++++++
 135 files changed, 1263 insertions(+), 556 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16cb2a2..26a70bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,9 +41,9 @@ SET(VENDOR "Gert Wollny")
 SET(PACKAGE_NAME "mia")
 SET(MAJOR_VERSION 2)
 SET(MINOR_VERSION 0)
-SET(MICRO_VERSION 11)
-SET(INTERFACE_AGE 3)
-SET(BINARY_AGE    3)
+SET(MICRO_VERSION 12)
+SET(INTERFACE_AGE 4)
+SET(BINARY_AGE    4)
 
 SET(PACKAGE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
 SET(VERSION "${MAJOR_VERSION}.${MINOR_VERSION}")
@@ -72,6 +72,25 @@ INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/cmake/macros.cmake)
 INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/cmake/pluginmacro.cmake)
 INCLUDE (CheckTypeSize)
 
+include(CheckCXXCompilerFlag)
+
+MESSAGE("CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
+IF(UNIX)
+  CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_GNU_CXX11_FLAG)
+  IF(HAS_GNU_CXX11_FLAG)
+    SET(CXX_11_FLAG "-std=c++11")
+  ELSE(HAS_GNU_CXX11_FLAG)
+    CHECK_CXX_COMPILER_FLAG("-std=c++0x" HAS_GNU_CXX0X_FLAG)
+    IF(HAS_GNU_CXX0X_FLAG)
+      SET(CXX_11_FLAG "-std=c++0x")
+    ELSE(HAS_GNU_CXX0X_FLAG)
+      MESSAGE(WARNING "Don't know how to enable C++11, if you are lucky, they are enabled by default")
+    ENDIF(HAS_GNU_CXX0X_FLAG)
+  ENDIF(HAS_GNU_CXX11_FLAG)
+  
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  ${CXX_11_FLAG}")
+ENDIF(UNIX)
+
 INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/cmake/checkCpp0xAuto.cmake)
 INCLUDE (${CMAKE_CURRENT_SOURCE_DIR}/cmake/checkCpp0xLambda.cmake)
 
@@ -452,6 +471,7 @@ IF(BUILD_EXAMPLES)
 ENDIF(BUILD_EXAMPLES)
 
 ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(test)
 ADD_SUBDIRECTORY(doc)
 
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/miacore.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/miacore-${VERSION}.pc)
@@ -470,6 +490,16 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mia2dmyocardperf-${VERSION}.pc
   DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/miamesh-${VERSION}.pc DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
 
+GET_PROPERTY(HAVE_DCMTK GLOBAL PROPERTY HAVE_DCMTK_PROP DEFINED)
+GET_PROPERTY(HAVE_HDF5 GLOBAL PROPERTY HAVE_HDF5_PROP DEFINED)
+GET_PROPERTY(HAVE_VISTAIO GLOBAL PROPERTY HAVE_VISTAIO_PROP DEFINED)
+GET_PROPERTY(HAVE_VTK GLOBAL PROPERTY HAVE_VTK_PROP DEFINED)
+GET_PROPERTY(HAVE_OPENEXR GLOBAL PROPERTY HAVE_OPENEXR_PROP DEFINED)
+GET_PROPERTY(HAVE_PNG GLOBAL PROPERTY HAVE_PNG_PROP DEFINED)
+GET_PROPERTY(HAVE_TIFF GLOBAL PROPERTY HAVE_TIFF_PROP DEFINED)
+GET_PROPERTY(HAVE_JPG GLOBAL PROPERTY HAVE_JPG_PROP DEFINED)
+GET_PROPERTY(HAVE_NLOPT GLOBAL PROPERTY HAVE_NLOPT_PROP DEFINED)
+
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/miaconfig.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/miaconfig.h)
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
 
diff --git a/ChangeLog b/ChangeLog
index 406bb9d..229385c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+
+2.0.12
+
+  Fixes for tracked bugs:
+
+  * #49:  Parallize the 3D scale filter
+  * #125: Make slicelocation and slicespacing non-obligatory
+  * #127: Correct documentation and output to refers to 2D data.
+  * #128: Add program to convert multi-record 2D image to 3D image
+
+  Partial fixes:
+
+  * #126: (partially) add override for do_get_preferred_suffix()
+  * #129: (partial) move optional plug-ins that depend on external
+          libraries to /addons
+
+  Additional fixes:
+
+  * Fix 147 issues reported by Coverty http://scan.coverity.com
+  * Dissmiss 37 issues reported by Coverty als intentional or false positive
+
+  * wavelet slope statistics will now throw an exception if the slope is too short
+  * set the C++11 flag correctly in UNIX
+  * Correct strides when writing to the 2D output tensor field.
+
 2.0.11
 
   Fixes of tracked bugs:
diff --git a/addons/CMakeLists.txt b/addons/CMakeLists.txt
index db0fd88..0ca878b 100644
--- a/addons/CMakeLists.txt
+++ b/addons/CMakeLists.txt
@@ -19,6 +19,10 @@
 INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}")
 
 ADD_SUBDIRECTORY(dicom   )
+ADD_SUBDIRECTORY(jpg )
 ADD_SUBDIRECTORY(openexr )
+ADD_SUBDIRECTORY(nlopt )
+ADD_SUBDIRECTORY(png )
+ADD_SUBDIRECTORY(tiff )
 ADD_SUBDIRECTORY(vtk   )
 ADD_SUBDIRECTORY(vistaio )
diff --git a/addons/dicom/CMakeLists.txt b/addons/dicom/CMakeLists.txt
index 5706a66..1e591ff 100644
--- a/addons/dicom/CMakeLists.txt
+++ b/addons/dicom/CMakeLists.txt
@@ -27,6 +27,7 @@ SET(image3dio_path ${PLUGIN_INSTALL_PATH}/3dimage/io)
 IF (WITH_DCMTK)
   FIND_PACKAGE(DCMTKnew)
   IF(DCMTK_FOUND)
+    DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_DCMTK_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
     SET(dicom4mia_deps mia3d ${DCMTK_LIBRARIES})
     MIA_ADD_LIBRARY(dicom4mia "${dicom4mia_SOURCES}" "${dicom4mia_deps}")
     INSTALL_BASE(dicom4mia)
diff --git a/addons/dicom/dcm2d.cc b/addons/dicom/dcm2d.cc
index 0b38f11..b52c516 100644
--- a/addons/dicom/dcm2d.cc
+++ b/addons/dicom/dcm2d.cc
@@ -81,6 +81,11 @@ const string CDicom2DImageIOPlugin::do_get_descr() const
 	return "2D image io for DICOM";
 }
 
+std::string CDicom2DImageIOPlugin::do_get_preferred_suffix() const
+{
+	return "dcm"; 
+}
+
 
 extern "C" EXPORT  CPluginBase *get_plugin_interface()
 {
diff --git a/addons/dicom/dcm2d.hh b/addons/dicom/dcm2d.hh
index f5875cf..43302bd 100644
--- a/addons/dicom/dcm2d.hh
+++ b/addons/dicom/dcm2d.hh
@@ -32,6 +32,7 @@ private:
 	PData do_load(const std::string& fname) const;
 	bool do_save(const std::string& fname, const Data& data) const;
 	const std::string do_get_descr() const;
+	std::string do_get_preferred_suffix() const; 
 };
 
 NS_END
diff --git a/addons/dicom/dcm3d.cc b/addons/dicom/dcm3d.cc
index 7d8c7fa..784a706 100644
--- a/addons/dicom/dcm3d.cc
+++ b/addons/dicom/dcm3d.cc
@@ -76,8 +76,13 @@ typedef map<PAttribute, CImageSeries, attr_less> CAquisitions;
 
 struct C3DImageCreator: public TFilter<bool> {
 	C3DImageCreator(size_t nz): m_nz(nz),
-				    m_delta_z(0.0) {
-	};
+				    m_z(0),
+				    m_slice_pos(0.0), 
+				    m_delta_z(0.0), 
+				    m_has_slice_location(false)
+		
+		{
+		};
 
 	template <typename T>
 	bool operator() ( const T2DImage<T>& image);
@@ -91,21 +96,27 @@ private:
 	float m_delta_z;
 	C2DBounds m_size2d;
 	C2DFVector m_pixel_size;
+	bool m_has_slice_location; 
 };
 
 template <typename T>
 bool C3DImageCreator::operator() ( const T2DImage<T>& image)
 {
+
 	T3DImage<T> *target = NULL;
 	if (!m_result) {
+		cvdebug() << "read first slice\n"; 
 		m_size2d = image.get_size();
 		target = new T3DImage<T>(C3DBounds(m_size2d.x, m_size2d.y, m_nz), image);
 		m_result.reset(target);
 		m_z = 0;
 		m_pixel_size = image.get_pixel_size();
-		m_slice_pos = image.template get_attribute_as<float>(IDSliceLocation);
+		m_has_slice_location = image.has_attribute(IDSliceLocation); 
+		if (m_has_slice_location) 
+			m_slice_pos = image.template get_attribute_as<float>(IDSliceLocation);
 		m_result->delete_attribute("pixel");
 	}else {
+		cvdebug() << "read slice "<< m_z << "\n"; 
 		target = dynamic_cast<T3DImage<T> *>(m_result.get());
 		if (!target) {
 			throw invalid_argument("Series input images have different pixel type");
@@ -113,9 +124,14 @@ bool C3DImageCreator::operator() ( const T2DImage<T>& image)
 		if (m_size2d != image.get_size()) {
 			throw invalid_argument("Series input images have different slice size");
 		}
-		float new_slice_pos = image.template get_attribute_as<float>(IDSliceLocation);
-		m_delta_z = new_slice_pos - m_slice_pos;
-		m_slice_pos = new_slice_pos;
+		if (m_has_slice_location) {
+			float new_slice_pos = image.template get_attribute_as<float>(IDSliceLocation);
+			m_delta_z = new_slice_pos - m_slice_pos;
+			m_slice_pos = new_slice_pos;
+		}else{
+			m_delta_z = 0.0; 
+			cvwarn() << "DICOM: 3D, images have no slice location, the data propably  doesn't constitute a volume\n";
+		}
 	}
 	assert(m_z < m_nz);
 	target->put_data_plane_xy(m_delta_z < 0 ? m_nz - 1 - m_z: m_z, image);
@@ -274,6 +290,8 @@ struct CSliceSaver: public TFilter<bool>
 };
 
 CSliceSaver::CSliceSaver(const string& fname):
+	m_series(0), 
+	m_slice(0),
 	m_location(0)
 {
 	// filename split the
diff --git a/addons/dicom/dicom4mia.cc b/addons/dicom/dicom4mia.cc
index 4a87a99..aeee4bd 100644
--- a/addons/dicom/dicom4mia.cc
+++ b/addons/dicom/dicom4mia.cc
@@ -121,6 +121,10 @@ struct CDicomReaderData {
 
 
 	C2DFVector getPixelSize();
+
+	C2DFVector getImagePixelSpacing(); 
+
+
 };
 
 
@@ -169,10 +173,14 @@ C2DFVector CDicomReader::get_pixel_size() const
 	return impl->getPixelSize();
 }
 
-C3DFVector CDicomReader::get_voxel_size() const
+C3DFVector CDicomReader::get_voxel_size(bool warn) const
 {
 	auto size2d = impl->getPixelSize();
-	auto thinkness = impl->getFloat64(DCM_SpacingBetweenSlices, true,0); 
+	auto thinkness = impl->getFloat64(DCM_SpacingBetweenSlices, false,0); 
+	if (thinkness <= 0.0 && warn) 
+		cvwarn() << "DICOM: 3D multiframe image doesn't provide a spacing between slices, most likely "
+			 << "the input file does not constitute a volume"; 
+
 	return C3DFVector(size2d.x, size2d.y, thinkness); 
 }
 
@@ -239,7 +247,7 @@ P3DImage CDicomReader::load_image3d()const
 	// get pixel data
 	impl->getPixelData(result->begin(), result->size());
 
-	result->set_voxel_size(this->get_voxel_size());
+	result->set_voxel_size(this->get_voxel_size(true));
 
 
 	const SLookupInit *attr_table = lookup_init;
diff --git a/addons/dicom/dicom4mia.hh b/addons/dicom/dicom4mia.hh
index 19ed802..3aeae60 100644
--- a/addons/dicom/dicom4mia.hh
+++ b/addons/dicom/dicom4mia.hh
@@ -63,7 +63,7 @@ public:
 
 	std::string get_attribute(const std::string& name, bool required)const;
 	C2DFVector get_pixel_size() const;
-	C3DFVector get_voxel_size() const;
+	C3DFVector get_voxel_size(bool warn_no_z) const;
 
 	P2DImage get_image() const;
 
diff --git a/mia/2d/rgbio/CMakeLists.txt b/addons/jpg/CMakeLists.txt
similarity index 61%
copy from mia/2d/rgbio/CMakeLists.txt
copy to addons/jpg/CMakeLists.txt
index e0e3763..016bad2 100644
--- a/mia/2d/rgbio/CMakeLists.txt
+++ b/addons/jpg/CMakeLists.txt
@@ -16,29 +16,21 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
-PLUGIN_WITH_PREFIX2("rgbimage" "io" bmp "${MIA2DLIBS}" )
+OPTION(WITH_JPEG "enable support for JPEG gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
 
-IF(PNG_FOUND)
-  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" png "${PNG_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
-ENDIF(PNG_FOUND)
-
-IF (FALSE)
-IF(TIFF_FOUND)
-  SET(TIFF_LINK_LIBS ${MIA2DLIBS} ${TIFF_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" tiff "${TIFF_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
-ENDIF(TIFF_FOUND)
-
-ENDIF(FALSE)
+IF(WITH_JPEG)
+  IF(STRICT_DEPENDECIES)
+    FIND_PACKAGE(JPEG REQUIRED)
+  ELSE(STRICT_DEPENDECIES)
+    FIND_PACKAGE(JPEG)
+  ENDIF(STRICT_DEPENDECIES)
+ENDIF(WITH_JPEG)
 
 IF(JPEG_FOUND)
+  DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_JPG_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
   SET(JPEG_LINK_LIBS ${MIA2DLIBS} ${JPEG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" jpg "${JPEG_LINK_LIBS}" "${rgbimage2dio_path}")
   INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
-ENDIF(JPEG_FOUND)
-
-
-
 
+  PLUGIN_WITH_PREFIX2("2dimage" "io" jpg-gray "${JPEG_LINK_LIBS}")
+  PLUGIN_WITH_PREFIX2("rgbimage" "io" jpg-rgb "${JPEG_LINK_LIBS}" "${rgbimage2dio_path}")
+ENDIF(JPEG_FOUND)
diff --git a/mia/2d/io/jpg.cc b/addons/jpg/jpg-gray.cc
similarity index 100%
rename from mia/2d/io/jpg.cc
rename to addons/jpg/jpg-gray.cc
diff --git a/mia/2d/rgbio/jpg.cc b/addons/jpg/jpg-rgb.cc
similarity index 100%
rename from mia/2d/rgbio/jpg.cc
rename to addons/jpg/jpg-rgb.cc
diff --git a/mia/core/minimizer/CMakeLists.txt b/addons/nlopt/CMakeLists.txt
similarity index 81%
copy from mia/core/minimizer/CMakeLists.txt
copy to addons/nlopt/CMakeLists.txt
index 20b8906..3ada9ae 100644
--- a/mia/core/minimizer/CMakeLists.txt
+++ b/addons/nlopt/CMakeLists.txt
@@ -16,12 +16,6 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
-SET(GSLOPTLIBS ${MIACORE} ${GSL_LIBRARIES})
-PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" gsl "${GSLOPTLIBS}")
-
-SET(NEEDED_LIBS miacore "${NEEDED_LIBS}")
-PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" gdsq "${NEEDED_LIBS}")
-
 OPTION(WITH_NLOPT "enable support for nlopt nonlinear optimizers" ${SEARCH_LIBS_DEFAULT})
 IF(WITH_NLOPT)
 
@@ -30,7 +24,8 @@ IF(WITH_NLOPT)
   ENDIF(NOT NLOPT_LIBRARIES) 
 
   IF(NLOPT_LIBRARIES) 
-    SET(NLOPTLIBS ${MIACORE} ${NLOPT_LIBRARIES})
+    DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_NLOPT_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
+    SET(NLOPTLIBS miacore ${NLOPT_LIBRARIES})
     PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" nlopt "${NLOPTLIBS}")
   ELSE (NLOPT_LIBRARIES)
     IF(STRICT_DEPENDECIES)
@@ -38,7 +33,3 @@ IF(WITH_NLOPT)
     ENDIF(STRICT_DEPENDECIES)
   ENDIF(NLOPT_LIBRARIES)
 ENDIF(WITH_NLOPT)
-
-
-
-
diff --git a/mia/core/minimizer/nlopt.cc b/addons/nlopt/nlopt.cc
similarity index 99%
rename from mia/core/minimizer/nlopt.cc
rename to addons/nlopt/nlopt.cc
index 7e6163f..935f084 100644
--- a/mia/core/minimizer/nlopt.cc
+++ b/addons/nlopt/nlopt.cc
@@ -18,7 +18,7 @@
  *
  */
 
-#include <mia/core/minimizer/nlopt.hh>
+#include <addons/nlopt/nlopt.hh>
 #include <stdexcept>
 
 NS_BEGIN(nlopt)
diff --git a/mia/core/minimizer/nlopt.hh b/addons/nlopt/nlopt.hh
similarity index 100%
rename from mia/core/minimizer/nlopt.hh
rename to addons/nlopt/nlopt.hh
diff --git a/mia/core/minimizer/test_nlopt.cc b/addons/nlopt/test_nlopt.cc
similarity index 99%
rename from mia/core/minimizer/test_nlopt.cc
rename to addons/nlopt/test_nlopt.cc
index fb6ebee..f7f946f 100644
--- a/mia/core/minimizer/test_nlopt.cc
+++ b/addons/nlopt/test_nlopt.cc
@@ -19,7 +19,7 @@
  */
 
 #include <mia/internal/autotest.hh>
-#include <mia/core/minimizer/nlopt.hh>
+#include <addons/nlopt/nlopt.hh>
 using namespace mia;
 using namespace nlopt; 
 
diff --git a/addons/openexr/2dimgexr.cc b/addons/openexr/2dimgexr.cc
index 0b34b5f..73f926e 100644
--- a/addons/openexr/2dimgexr.cc
+++ b/addons/openexr/2dimgexr.cc
@@ -102,11 +102,10 @@ CEXR2DImageIOPlugin::PData  CEXR2DImageIOPlugin::do_load(const string& filename)
 		file.readPixels (dw.min.y, dw.max.y);
 		return result;
 	}
-	catch (...) {
-		return CEXR2DImageIOPlugin::PData();
+	catch (const std::exception& x) {
+		// should add an debug message 
+		cvwarn() << "OpenXER: failed reading image from '"<< filename<< "':" << x.what() << "\n"; 
 	}
-
-
 	return CEXR2DImageIOPlugin::PData();
 }
 
diff --git a/addons/openexr/2dvfexr.cc b/addons/openexr/2dvfexr.cc
index 7b255ce..b5df707 100644
--- a/addons/openexr/2dvfexr.cc
+++ b/addons/openexr/2dvfexr.cc
@@ -98,11 +98,11 @@ CEXR2DVFIOPlugin::PData  CEXR2DVFIOPlugin::do_load(const string& filename) const
 		file.readPixels (dw.min.y, dw.max.y);
 		return vf;
 	}
-	catch (...) {
-		return CEXR2DVFIOPlugin::PData();
-	}
-
 
+	catch (const std::exception& x) {
+		// should add an debug message 
+		cvwarn() << "OpenXER: failed reading vector field from '"<< filename<< "':" << x.what() << "\n"; 
+	}
 	return CEXR2DVFIOPlugin::PData();
 }
 
diff --git a/addons/openexr/CMakeLists.txt b/addons/openexr/CMakeLists.txt
index 5a93087..abc2d7a 100644
--- a/addons/openexr/CMakeLists.txt
+++ b/addons/openexr/CMakeLists.txt
@@ -28,7 +28,7 @@ IF(WITH_OpenEXR)
   
   
   IF( EXR_LIBRARIES AND EXR_INCLUDE_DIRS )
-    
+    DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_OPENEXR_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
     SET(image2dio_path ${PLUGIN_INSTALL_PATH}/2dimage/io)
     SET(image3dio_path ${PLUGIN_INSTALL_PATH}/3dimage/io)
     SET(vf2dio_path ${PLUGIN_INSTALL_PATH}/2dvf/io)
diff --git a/mia/2d/rgbio/CMakeLists.txt b/addons/png/CMakeLists.txt
similarity index 61%
copy from mia/2d/rgbio/CMakeLists.txt
copy to addons/png/CMakeLists.txt
index e0e3763..30b878a 100644
--- a/mia/2d/rgbio/CMakeLists.txt
+++ b/addons/png/CMakeLists.txt
@@ -16,29 +16,26 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
-PLUGIN_WITH_PREFIX2("rgbimage" "io" bmp "${MIA2DLIBS}" )
+OPTION(WITH_PNG "enable support for PNG gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
 
-IF(PNG_FOUND)
-  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" png "${PNG_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
-ENDIF(PNG_FOUND)
+IF (WITH_PNG)
+  IF(STRICT_DEPENDECIES)
+    FIND_PACKAGE(PNG REQUIRED)
+  ELSE(STRICT_DEPENDECIES)
+    FIND_PACKAGE(PNG)
+  ENDIF(STRICT_DEPENDECIES)
+ENDIF(WITH_PNG)
 
-IF (FALSE)
-IF(TIFF_FOUND)
-  SET(TIFF_LINK_LIBS ${MIA2DLIBS} ${TIFF_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" tiff "${TIFF_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
-ENDIF(TIFF_FOUND)
 
-ENDIF(FALSE)
+IF(PNG_FOUND)
 
-IF(JPEG_FOUND)
-  SET(JPEG_LINK_LIBS ${MIA2DLIBS} ${JPEG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" jpg "${JPEG_LINK_LIBS}" "${rgbimage2dio_path}")
-  INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
-ENDIF(JPEG_FOUND)
+  DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_PNG_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
 
+  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
+  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
 
+  PLUGIN_WITH_PREFIX2("2dimage" "io" png-gray "${PNG_LINK_LIBS}")
+  PLUGIN_WITH_PREFIX2("rgbimage" "io" png-rgb "${PNG_LINK_LIBS}" )
 
 
+ENDIF(PNG_FOUND)
diff --git a/mia/2d/io/png.cc b/addons/png/png-gray.cc
similarity index 100%
rename from mia/2d/io/png.cc
rename to addons/png/png-gray.cc
diff --git a/mia/2d/rgbio/png.cc b/addons/png/png-rgb.cc
similarity index 100%
rename from mia/2d/rgbio/png.cc
rename to addons/png/png-rgb.cc
diff --git a/mia/2d/rgbio/CMakeLists.txt b/addons/tiff/CMakeLists.txt
similarity index 61%
copy from mia/2d/rgbio/CMakeLists.txt
copy to addons/tiff/CMakeLists.txt
index e0e3763..c14a48a 100644
--- a/mia/2d/rgbio/CMakeLists.txt
+++ b/addons/tiff/CMakeLists.txt
@@ -16,29 +16,20 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
-PLUGIN_WITH_PREFIX2("rgbimage" "io" bmp "${MIA2DLIBS}" )
+OPTION(WITH_TIFF "enable support for TIFF gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
 
-IF(PNG_FOUND)
-  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" png "${PNG_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
-ENDIF(PNG_FOUND)
+IF(WITH_TIFF)
+  IF(STRICT_DEPENDECIES)
+    FIND_PACKAGE(TIFF REQUIRED)
+  ELSE(STRICT_DEPENDECIES)
+    FIND_PACKAGE(TIFF)
+  ENDIF(STRICT_DEPENDECIES)
+ENDIF(WITH_TIFF)
 
-IF (FALSE)
 IF(TIFF_FOUND)
+  DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_TIFF_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
   SET(TIFF_LINK_LIBS ${MIA2DLIBS} ${TIFF_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" tiff "${TIFF_LINK_LIBS}" )
+  PLUGIN_WITH_PREFIX2("2dimage" "io" tiff "${TIFF_LINK_LIBS}")
   INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
 ENDIF(TIFF_FOUND)
 
-ENDIF(FALSE)
-
-IF(JPEG_FOUND)
-  SET(JPEG_LINK_LIBS ${MIA2DLIBS} ${JPEG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" jpg "${JPEG_LINK_LIBS}" "${rgbimage2dio_path}")
-  INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
-ENDIF(JPEG_FOUND)
-
-
-
-
diff --git a/mia/2d/io/tiff.cc b/addons/tiff/tiff.cc
similarity index 100%
rename from mia/2d/io/tiff.cc
rename to addons/tiff/tiff.cc
diff --git a/addons/vistaio/CMakeLists.txt b/addons/vistaio/CMakeLists.txt
index 982d377..2e825da 100644
--- a/addons/vistaio/CMakeLists.txt
+++ b/addons/vistaio/CMakeLists.txt
@@ -27,6 +27,7 @@ IF (USE_VISTAIO)
   endif (STRICT_DEPENDECIES)
   
   IF( VISTAIO_FOUND )
+    DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_VISTAIO_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
     INCLUDE_DIRECTORIES(${VISTAIO_INCLUDE_DIRS})
     LINK_DIRECTORIES(${VISTAIO_LIBRARY_DIRS})
     SET(VISTAIO_SRC vista4mia.cc)
diff --git a/addons/vistaio/test_vista4mia.cc b/addons/vistaio/test_vista4mia.cc
index 48168d9..0f8e907 100644
--- a/addons/vistaio/test_vista4mia.cc
+++ b/addons/vistaio/test_vista4mia.cc
@@ -341,9 +341,12 @@ const SProgramDescription description = {
 };
 
 int BOOST_TEST_CALL_DECL
-main( int argc, char* argv[] )
+do_main( int argc, char* argv[] )
 {
 	if (CCmdOptionList(description).parse(argc, argv) != CCmdOptionList::hr_no)
 		return 0; 
 	return ::boost::unit_test::unit_test_main( &init_unit_test_suite, argc, argv );
 }
+
+#include <mia/internal/main.hh>
+MIA_MAIN(do_main);
diff --git a/addons/vtk/CMakeLists.txt b/addons/vtk/CMakeLists.txt
index 87dfed4..103ba0c 100644
--- a/addons/vtk/CMakeLists.txt
+++ b/addons/vtk/CMakeLists.txt
@@ -25,6 +25,7 @@ IF(WITH_VTKIO)
     FIND_PACKAGE(VTK QUIET)
   endif (STRICT_DEPENDECIES)
   IF(VTK_FOUND)
+    DEFINE_PROPERTY(GLOBAL PROPERTY HAVE_VTK_PROP BRIEF_DOCS "yeah" FULL_DOCS "yeah")
     INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})
     SET(meshio_path ${PLUGIN_INSTALL_PATH}/mesh/io)
     SET(vfio_path "${PLUGIN_INSTALL_PATH}/3dvf/io")
diff --git a/addons/vtk/vtkimage.cc b/addons/vtk/vtkimage.cc
index 5a3b55a..523f7f9 100644
--- a/addons/vtk/vtkimage.cc
+++ b/addons/vtk/vtkimage.cc
@@ -225,7 +225,7 @@ CVtk3DImageIOPlugin::CVtk3DImageIOPlugin():
 	add_suffix(".vtk");
 	add_suffix(".VTK");
 	add_suffix(".vtkimage");
-	add_suffix(".VTKimage");
+	add_suffix(".VTKIMAGE");
 
 }
 
diff --git a/addons/vtk/vtkmesh.cc b/addons/vtk/vtkmesh.cc
index 0455136..aed23d3 100644
--- a/addons/vtk/vtkmesh.cc
+++ b/addons/vtk/vtkmesh.cc
@@ -218,9 +218,10 @@ PTriangleMesh CVtkMeshIO::do_load(string const &  filename) const
 	auto reader = vtkSmartPointer<vtkPolyDataReader>::New();
 	reader->SetFileName(filename.c_str());
 	auto mesh = reader->GetOutput(); 
-	mesh->Update(); 
 	if (!mesh)
 		return PTriangleMesh(); 
+
+	mesh->Update(); 
 	
 	auto vertices = read_vertices(*mesh); 
 	auto triangles = read_triangles(*vertices, *mesh); 
diff --git a/addons/vtk/vtkvf.cc b/addons/vtk/vtkvf.cc
index cd5d402..989b9b3 100644
--- a/addons/vtk/vtkvf.cc
+++ b/addons/vtk/vtkvf.cc
@@ -62,9 +62,9 @@ CVtk3DVFIOPlugin::PData CVtk3DVFIOPlugin::do_load(const string&  filename) const
 	auto reader = vtkSmartPointer<vtkStructuredPointsReader>::New(); 
 	reader->SetFileName(filename.c_str()); 
 	auto iovf = reader->GetOutput(); 
-	iovf->Update(); 
 	if (!iovf)
 		return PData(); 
+	iovf->Update(); 
 	
 	int dim = iovf->GetDataDimension();
 	if (dim != 3) {
@@ -73,9 +73,6 @@ CVtk3DVFIOPlugin::PData CVtk3DVFIOPlugin::do_load(const string&  filename) const
 	}
 
 	auto dims = iovf->GetDimensions();
-	if (dim != 3)
-		throw create_exception<invalid_argument>("3D Vtkvf load (", filename ,
-							 "): Expect 3 dimensions but got ", dim); 
 	C3DBounds size(dims[0], dims[1], dims[2]); 
 
 	int components = iovf->GetNumberOfScalarComponents(); 
diff --git a/config.h.cmake b/config.h.cmake
index dcae8fc..54a9254 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -18,6 +18,7 @@
 #define VENDOR  "@VENDOR@"
 #define MIA_SOURCE_ROOT "@SOURCE_ROOT@"
 #define MIA_BUILD_ROOT "@BUILD_ROOT@"
+#define PLUGIN_TEST_ROOT "@PLUGIN_TEST_ROOT@"
 
 #if defined(_MSC_VER)
 #  define DO_EXPORT __declspec(dllexport) 
@@ -32,4 +33,17 @@
 
 #cmakedefine HAVE_SYS_IOCTL_H 1
 
+
+#cmakedefine HAVE_DCMTK 1
+#cmakedefine HAVE_VISTAIO 1
+#cmakedefine HAVE_VTK 1
+#cmakedefine HAVE_OPENEXR 1
+#cmakedefine HAVE_HDF5 1
+#cmakedefine HAVE_PNG 1
+#cmakedefine HAVE_TIFF 1
+#cmakedefine HAVE_JPG 1
+
+#cmakedefine HAVE_NLOPT 1
+
+
 #endif
diff --git a/mia/2d/CMakeLists.txt b/mia/2d/CMakeLists.txt
index f6185aa..828145b 100644
--- a/mia/2d/CMakeLists.txt
+++ b/mia/2d/CMakeLists.txt
@@ -272,38 +272,6 @@ TEST_2DMIA(segpoint mia2dmyocardperf)
 
 
 #
-#  image IO options 
-#
-OPTION(WITH_PNG "enable support for PNG gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
-OPTION(WITH_TIFF "enable support for TIFF gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
-OPTION(WITH_JPEG "enable support for JPEG gray scale images IO and RGB saving" ${SEARCH_LIBS_DEFAULT})
-
-IF (WITH_PNG)
-  IF(STRICT_DEPENDECIES)
-    FIND_PACKAGE(PNG REQUIRED)
-  ELSE(STRICT_DEPENDECIES)
-    FIND_PACKAGE(PNG)
-  ENDIF(STRICT_DEPENDECIES)
-ENDIF(WITH_PNG)
-
-IF(WITH_TIFF)
-  IF(STRICT_DEPENDECIES)
-    FIND_PACKAGE(TIFF REQUIRED)
-  ELSE(STRICT_DEPENDECIES)
-    FIND_PACKAGE(TIFF)
-  ENDIF(STRICT_DEPENDECIES)
-ENDIF(WITH_TIFF)
-
-
-IF(WITH_JPEG)
-  IF(STRICT_DEPENDECIES)
-    FIND_PACKAGE(JPEG REQUIRED)
-  ELSE(STRICT_DEPENDECIES)
-    FIND_PACKAGE(JPEG)
-  ENDIF(STRICT_DEPENDECIES)
-ENDIF(WITH_JPEG)
-
-#
 # The plugin directories 
 #
 ADD_SUBDIRECTORY(cost      )
diff --git a/mia/2d/SegStar.cc b/mia/2d/SegStar.cc
index 9eb4fd1..5eaa82f 100644
--- a/mia/2d/SegStar.cc
+++ b/mia/2d/SegStar.cc
@@ -31,7 +31,8 @@
 NS_MIA_BEGIN
 using namespace std;
 
-CSegStar::CSegStar()
+CSegStar::CSegStar():
+	m_radius(0.0)
 {
 }
 
diff --git a/mia/2d/cost/ngf.hh b/mia/2d/cost/ngf.hh
index d48150a..cb767fd 100644
--- a/mia/2d/cost/ngf.hh
+++ b/mia/2d/cost/ngf.hh
@@ -100,11 +100,8 @@ private:
 	virtual void post_set_reference(const mia::C2DImage& ref); 
 
 	mia::C2DFVectorfield m_ng_ref;
-	bool m_jump_levels_valid;
-	float m_cost_baseline;
-
 	PEvaluator m_evaluator;
-	float m_intensity_scale;
+
 };
 
 class C2DNFGImageCostPlugin: public mia::C2DImageCostPlugin {
diff --git a/mia/2d/creator/circle.cc b/mia/2d/creator/circle.cc
index 2e404ed..8ab14f1 100644
--- a/mia/2d/creator/circle.cc
+++ b/mia/2d/creator/circle.cc
@@ -109,7 +109,7 @@ P2DImage C2DCircleCreator::do_create(const C2DBounds& size) const
 			dx = pow(dx, m_p);
 
 			dx += dy;
-			*p =  (dx > l) ? 0 : *p = move_range<T,is_float>::apply(cos( dx / l * m_f * M_PI ));
+			*p =  (dx > l) ? 0 : move_range<T,is_float>::apply(cos( dx / l * m_f * M_PI ));
 		}
 	}
 	return  P2DImage(result);
diff --git a/mia/2d/fftkernel.cc b/mia/2d/fftkernel.cc
index 4ea5da8..6c26827 100644
--- a/mia/2d/fftkernel.cc
+++ b/mia/2d/fftkernel.cc
@@ -31,9 +31,12 @@ const char* fft2d_kernel_data::data_descr = "fft2d";
 
 CFFT2DKernel::CFFT2DKernel():
 	m_size(0,0),
-	m_cbuffer(NULL),
-	m_fbuffer(NULL),
-	m_scale(1.0)
+	m_cbuffer(nullptr),
+	m_fbuffer(nullptr),
+	m_scale(1.0), 
+	m_forward_plan(nullptr), 
+	m_backward_plan(nullptr), 
+	m_realsize_x(0)
 {
 }
 
diff --git a/mia/2d/filter/aniso.cc b/mia/2d/filter/aniso.cc
index 79b6a3e..d56c31d 100644
--- a/mia/2d/filter/aniso.cc
+++ b/mia/2d/filter/aniso.cc
@@ -85,7 +85,10 @@ C2DAnisoDiff::C2DAnisoDiff(int maxiter, float epsilon, float k, FEdgeStopping ed
 	m_k(k),
 	m_edge_stop(edge_stop),
 	m_neighbourhood(neighbourhood),
-	m_histogramfeeder(0,256,256)
+	m_histogramfeeder(0,256,256), 
+	m_sigma_e(0.0), 
+	m_gamma(0.0), 
+	m_sigma(0.0)
 {
 	if (m_neighbourhood != 4 && m_neighbourhood != 8) {
 		stringstream errmsg;
diff --git a/mia/2d/filter/mask.cc b/mia/2d/filter/mask.cc
index f5f429a..ace88e9 100644
--- a/mia/2d/filter/mask.cc
+++ b/mia/2d/filter/mask.cc
@@ -115,7 +115,8 @@ C2DMask::result_type C2DMask::operator () (const T2DImage<T>& data) const
 	P2DImage image = (*in_image_list)[0];
 
 	if (image->get_pixel_type() == it_bit) {
-		const C2DBitImage *mask = dynamic_cast<const C2DBitImage*>(image.get());
+		// use static cast because type is already tested. 
+		const C2DBitImage *mask = static_cast<const C2DBitImage*>(image.get());
 		C2DMaskDispatch m(mask, m_fill, m_inverse, true);
 		return m(data);
 	} else {
diff --git a/mia/2d/filter/mean.cc b/mia/2d/filter/mean.cc
index 5c9fd05..9960002 100644
--- a/mia/2d/filter/mean.cc
+++ b/mia/2d/filter/mean.cc
@@ -36,7 +36,13 @@ template <typename T, bool value>
 struct __dispatch_filter {
 	static T apply(const T2DImage<T>& data, int cx, int cy, int hw) {
 		double result = 0.0; 
-		int n = 0; 
+		int n = 0;
+		// 
+		// Coverty complains about this: 1128688, 1128687 
+		// 
+		// hw >= 0, cy >= 0 && cy < data.get_size().y
+		// therefore n>=1 
+		// 
 		for (int y = cy - hw; y <= cy + hw; ++y) {
 			if ( y >= 0 && y < (int)data.get_size().y) 
 				for (int x = cx - hw; x <= cx + hw; ++x) {
@@ -52,9 +58,12 @@ struct __dispatch_filter {
 
 template <typename T> 
 struct __dispatch_filter<T, true> {
-	static T apply(const T2DImage<T>& data, int cx, int cy, int hw) {
+	static T apply(const T2DImage<T>& data, int cx, int cy, int  hw) {
 		double result = 0.0; 
 		int n = 0; 
+		// 
+		// see above. Coverty  1128688, 1128687
+		// 
 		for (int y = cy - hw; y <= cy + hw; ++y) {
 			if ( y >= 0 && y < (int)data.get_size().y) 
 				for (int x = cx - hw; x <= cx + hw; ++x) {
@@ -91,6 +100,7 @@ template <typename T>
 C2DMean::result_type C2DMean::operator () (const T2DImage<T>& data) const
 {
 	TRACE_FUNCTION; 
+	assert(m_hw >=0); 
 	const bool is_floating_point = boost::is_floating_point<T>::value; 
 
 	T2DImage<T> *tresult = new T2DImage<T>(data.get_size(), data);
diff --git a/mia/2d/filter/test_mlv.cc b/mia/2d/filter/test_mlv.cc
index 7a53c08..7435c3d 100644
--- a/mia/2d/filter/test_mlv.cc
+++ b/mia/2d/filter/test_mlv.cc
@@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE( test_mlv )
 						sum2 += val * val;
 						++n;
 					}
-				float m = mu(x,y) = sum / n;
+				float m = n>0 ? mu(x,y) = sum / n : 0;
 				sigma(x,y) = (n > 1) ? (sum2 - n * m * m) / (n - 1) : 0.0f;
 			}
 
diff --git a/mia/2d/fuzzyClusterSolverCG.cc b/mia/2d/fuzzyClusterSolverCG.cc
index 3ec6f1a..f772d57 100644
--- a/mia/2d/fuzzyClusterSolverCG.cc
+++ b/mia/2d/fuzzyClusterSolverCG.cc
@@ -68,6 +68,13 @@ C2DSolveCG::C2DSolveCG (C2DFImage& w1, C2DFImage& f1, C2DFImage& gain_image, dou
 	m_scale2(m_count),
 	m_border(m_count),
 
+	m_r1rho1(0.0), 
+	m_r2rho2(0.0),
+	m_normr0(0.0),
+	m_q(0.0), 
+	m_e(0.0),
+	m_sprod(0.0),
+
 	m_min_res(m_res),
 	m_relres(r_res)
 
diff --git a/mia/2d/io/CMakeLists.txt b/mia/2d/io/CMakeLists.txt
index 6309bba..b7d3822 100644
--- a/mia/2d/io/CMakeLists.txt
+++ b/mia/2d/io/CMakeLists.txt
@@ -26,23 +26,6 @@ ADD_CUSTOM_TARGET(2d-vfio_testdir mkdir -p ${PLUGIN_TEST_ROOT}/${vf2dio_path})
 PLUGIN_WITH_PREFIX2("2dimage" "io" bmp "${MIA2DLIBS}")
 PLUGIN_WITH_PREFIX2("2dimage" "io" raw "${MIA2DLIBS}")
 
-IF(PNG_FOUND)
-  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("2dimage" "io" png "${PNG_LINK_LIBS}")
-  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
-ENDIF(PNG_FOUND)
-
-IF(TIFF_FOUND)
-  SET(TIFF_LINK_LIBS ${MIA2DLIBS} ${TIFF_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("2dimage" "io" tiff "${TIFF_LINK_LIBS}")
-  INCLUDE_DIRECTORIES(${TIFF_INCLUDE_DIR})
-ENDIF(TIFF_FOUND)
-
-IF(JPEG_FOUND)
-  SET(JPEG_LINK_LIBS ${MIA2DLIBS} ${JPEG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("2dimage" "io" jpg "${JPEG_LINK_LIBS}")
-  INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
-ENDIF(JPEG_FOUND)
 
 
 
diff --git a/mia/2d/io/bmp.cc b/mia/2d/io/bmp.cc
index f22f19a..6d9708a 100644
--- a/mia/2d/io/bmp.cc
+++ b/mia/2d/io/bmp.cc
@@ -123,7 +123,7 @@ static P2DImage  read_bit_pixels(CFile& image, unsigned int width, unsigned int
 {
         TRACE("read_bit_pixels");
         C2DBitImage *result = new C2DBitImage(C2DBounds(width, height));
-
+	P2DImage presult(result); 
 	for (int y = height-1; y >= 0; --y) {
 		int row_count = 0;
 		C2DBitImage::iterator  p = result->begin() + width * y;
@@ -135,15 +135,18 @@ static P2DImage  read_bit_pixels(CFile& image, unsigned int width, unsigned int
 		// eat the padding bytes
 		int remain = (4 - row_count % 4) % 4;
 		while (remain--) {
-			cverb << fgetc(image) << " ";
+			if (fgetc(image) == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
+			
 		}
 	}
-        return P2DImage(result);
+        return presult;
 }
 
 static P2DImage  read_4bit_pixels(CFile& image, unsigned int width, unsigned int height)
 {
 	C2DBitImage *result = new C2DBitImage(C2DBounds(width, height));
+	P2DImage presult(result); 
 	cvdebug() << "read_4bit_pixels\n";
 
 	for (int y = height-1; y >= 0; --y) {
@@ -151,22 +154,26 @@ static P2DImage  read_4bit_pixels(CFile& image, unsigned int width, unsigned int
 		C2DBitImage::iterator p = result->begin() + width * y;
 		for (size_t x = 0; x < width; x += 2, ++row_count) {
 			int inbyte = fgetc(image);
+			if (inbyte == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
 			*p++ = (inbyte >> 4) & 0xF;
 			*p++ = inbyte & 0xF;
 		}
 		// eat the padding bytes
 		int remain = (4 - row_count % 4) % 4;
 		while (remain--) {
-			fgetc(image);
+			if (fgetc(image) == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
 		}
 	}
 
-	return P2DImage(result);
+	return presult;
 }
 
 static P2DImage  read_8bit_pixels_uc(CFile& image, unsigned int width, unsigned int height)
 {
 	C2DUBImage *result = new C2DUBImage(C2DBounds(width, height));
+	P2DImage presult(result); 
 	int row_count =  (4 - width % 4) % 4;
 	cvdebug() << "read_8bit_pixels_nc\n";
 
@@ -177,18 +184,19 @@ static P2DImage  read_8bit_pixels_uc(CFile& image, unsigned int width, unsigned
 
 		int remain = row_count;
 		while (remain--) {
-			fgetc(image);
+			if (fgetc(image) == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
 		}
 	}
 	cvdebug() << "read_8bit_pixels_nc done\n";
-	return P2DImage(result);
+	return presult;
 }
 
 static P2DImage  read_8bit_pixels_c(CFile& image, unsigned int width, unsigned int height)
 {
         TRACE("read_8bit_pixels_c");
         C2DUBImage *result = new C2DUBImage(C2DBounds(width, height));
-
+	P2DImage presult(result); 
 
 	int x = 0;
 	int y = height-1;
@@ -197,6 +205,9 @@ static P2DImage  read_8bit_pixels_c(CFile& image, unsigned int width, unsigned i
 
 		int n = fgetc(image);
 		int c = fgetc(image);
+		if (n == EOF || c == EOF) 
+			throw runtime_error("BMP::Load: incomplete image");
+
 
 		if (n == 0) {
 			switch (c) {
@@ -208,17 +219,27 @@ static P2DImage  read_8bit_pixels_c(CFile& image, unsigned int width, unsigned i
 			case 1: y = -1;
 				break;
 
-			case 2:
-				x += fgetc(image);
-				y -= fgetc(image);
-				break;
+			case 2: {
+				const int dx = fgetc(image);
+				const int dy = fgetc(image);
+				if (dx == EOF || dy == EOF) 
+					throw runtime_error("BMP::Load: incomplete image");
+				x += dx; 
+				y -= dy; 
+			} break;
 
 			default: {
 				bool odd = c & 1;
-				while ( c-- )
-					(*result)(x++,y) = fgetc(image);
-				if (odd)
-					fgetc(image);
+				while ( c-- ) {
+					const int cc = fgetc(image);
+					if (cc == EOF) 
+						throw runtime_error("BMP::Load: incomplete image");
+					(*result)(x++,y) = cc; 
+				}
+				if (odd) {
+					if (fgetc(image) == EOF) 
+						throw runtime_error("BMP::Load: incomplete image");
+				}
 			}
 			}
 		}else{
@@ -227,13 +248,14 @@ static P2DImage  read_8bit_pixels_c(CFile& image, unsigned int width, unsigned i
 		}
 	}
 
-	return P2DImage(result);
+	return presult;
 }
 
 
 static P2DImage  read_16bit_pixels(CFile& image, unsigned int width, unsigned int height)
 {
 	C2DUSImage *result = new C2DUSImage(C2DBounds(width, height));
+	P2DImage presult(result); 
 	int row_count = width % 2;
 	cvdebug() << "read_16bit_pixels\n";
 
@@ -247,11 +269,13 @@ static P2DImage  read_16bit_pixels(CFile& image, unsigned int width, unsigned in
 #endif
 		int remain = row_count;
 		while (remain--) {
-			fgetc(image);
-			fgetc(image);
+			if (fgetc(image) == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
+			if (fgetc(image) == EOF) 
+				throw runtime_error("BPM::Load: incomplete image");
 		}
 	}
-	return P2DImage(result);
+	return presult;
 }
 
 
@@ -261,6 +285,7 @@ static P2DImage  read_24bit_pixels(CFile& image, unsigned int width, unsigned in
 	cvdebug() << "read_24bit_pixels\n";
 
 	C2DUIImage *result = new C2DUIImage(C2DBounds(width, height));
+	P2DImage presult(result); 
 
 	for (int y = height-1; y >= 0; --y) {
 		unsigned int *p = &(*result)(0,y);
@@ -271,7 +296,7 @@ static P2DImage  read_24bit_pixels(CFile& image, unsigned int width, unsigned in
 			ENDIANADAPT(*p);
 #endif
 	}
-	return P2DImage(result);
+	return presult;
 }
 
 #ifdef WORDS_BIGENDIAN
@@ -349,6 +374,21 @@ CBMP2DImageIO::PData CBMP2DImageIO::do_load(string const& filename)const
 		}
 	}
 
+	if ((info_header.width < 1) || (info_header.height < 1))
+		throw create_exception<runtime_error>("CBMP2DImageIO::load: Image has unsupported dimensions", 
+						      " width=", info_header.width, ", height=", 
+						      info_header.height);
+	
+  
+	// this is actually a non-sense test but it should silence the Coverty warning about 
+	// the tainted variables. 
+	size_t h = info_header.height; 
+	size_t w = info_header.width; 
+	if (h > numeric_limits<int>::max() || w > numeric_limits<int>::max()) 
+		throw create_exception<runtime_error>("CBMP2DImageIO::load: Image has too big", 
+						      " width=", info_header.width, ", height=", 
+						      info_header.height);
+	
 	PData result = PData(new C2DImageVector());
 
 
diff --git a/mia/2d/model/navier.cc b/mia/2d/model/navier.cc
index f9db782..ddfbf25 100644
--- a/mia/2d/model/navier.cc
+++ b/mia/2d/model/navier.cc
@@ -61,7 +61,6 @@ void C2DNavierRegModel::do_solve(const C2DFVectorfield& b, C2DFVectorfield& v) c
 	size_t i = 0;
 
 	do {
-		++i;
 		residuum = 0;
 
 		C2DFVectorfield::const_iterator ib = b.begin() + b.get_size().x;
@@ -76,9 +75,9 @@ void C2DNavierRegModel::do_solve(const C2DFVectorfield& b, C2DFVectorfield& v) c
 		if (i ==0)
 			start_residuum = residuum;
 
-		if (residuum < 1)
+		if (residuum < 0.01)
 			break;
-
+		++i;
 
 	} while (i < m_max_iter && residuum / start_residuum > m_epsilon);
 }
diff --git a/mia/2d/model/navier.hh b/mia/2d/model/navier.hh
index 9d014d8..1fb5f08 100644
--- a/mia/2d/model/navier.hh
+++ b/mia/2d/model/navier.hh
@@ -49,7 +49,7 @@ private:
 
 	float m_mu;
 	float m_lambda;
-	float m_a1,m_a, m_b, m_c, m_a_b, m_b_4;
+	float m_a, m_c, m_a_b, m_b_4;
 	float m_omega;
 	float m_epsilon;
 	size_t m_max_iter;
diff --git a/mia/2d/model/naviera.hh b/mia/2d/model/naviera.hh
index 9d4cdc2..2c6f5d7 100644
--- a/mia/2d/model/naviera.hh
+++ b/mia/2d/model/naviera.hh
@@ -46,7 +46,7 @@ private:
 
 	float m_mu;
 	float m_lambda;
-	float m_a1,m_a, m_b, m_c, m_a_b, m_b_4;
+	float m_a, m_a_b, m_b_4;
 	float m_omega;
 	float m_epsilon;
 	size_t m_max_iter;
diff --git a/mia/2d/perfusion.cc b/mia/2d/perfusion.cc
index 176eaff..eb3ce0c 100644
--- a/mia/2d/perfusion.cc
+++ b/mia/2d/perfusion.cc
@@ -478,9 +478,9 @@ retry:
 		label = ::mia::filter(GetClosestRegionLabel(RV_center), *LV_candidates);
 		lv_pixels = ::mia::filter(GetRegionSize(label), *LV_candidates);
 		
-	} while (10 * npixels > rvlv_feature->get_size().x * rvlv_feature->get_size().y && nc < 7);
+	} while (10 * lv_pixels > rvlv_feature->get_size().x * rvlv_feature->get_size().y && nc < 7);
 	
-	if (10 * lv_pixels > rvlv_feature->get_size().x * rvlv_feature->get_size().y && nc == 7) {
+	if (10 * lv_pixels > rvlv_feature->get_size().x * rvlv_feature->get_size().y) {
 		cvmsg() << "LV classification failed\n"; 
 		return result;
 	}
diff --git a/mia/2d/rgbio/CMakeLists.txt b/mia/2d/rgbio/CMakeLists.txt
index e0e3763..768ae9a 100644
--- a/mia/2d/rgbio/CMakeLists.txt
+++ b/mia/2d/rgbio/CMakeLists.txt
@@ -18,12 +18,6 @@
 
 PLUGIN_WITH_PREFIX2("rgbimage" "io" bmp "${MIA2DLIBS}" )
 
-IF(PNG_FOUND)
-  SET(PNG_LINK_LIBS ${MIA2DLIBS} ${PNG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" png "${PNG_LINK_LIBS}" )
-  INCLUDE_DIRECTORIES(${PNG_PNG_INCLUDE_DIR})
-ENDIF(PNG_FOUND)
-
 IF (FALSE)
 IF(TIFF_FOUND)
   SET(TIFF_LINK_LIBS ${MIA2DLIBS} ${TIFF_LIBRARIES})
@@ -33,11 +27,6 @@ ENDIF(TIFF_FOUND)
 
 ENDIF(FALSE)
 
-IF(JPEG_FOUND)
-  SET(JPEG_LINK_LIBS ${MIA2DLIBS} ${JPEG_LIBRARIES})
-  PLUGIN_WITH_PREFIX2("rgbimage" "io" jpg "${JPEG_LINK_LIBS}" "${rgbimage2dio_path}")
-  INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR})
-ENDIF(JPEG_FOUND)
 
 
 
diff --git a/mia/2d/test_imageio.cc b/mia/2d/test_imageio.cc
index 6d32791..5d9141f 100644
--- a/mia/2d/test_imageio.cc
+++ b/mia/2d/test_imageio.cc
@@ -63,8 +63,9 @@ BOOST_AUTO_TEST_CASE( test_load_series )
 	test_image_list2.push_back(create_test_image(1,1,"proto3"));
 	
 
-	C2DImageIOPluginHandler::instance().save("test0.@", test_image_list1); 
-	C2DImageIOPluginHandler::instance().save("test1.@", test_image_list2); 
+	BOOST_REQUIRE(C2DImageIOPluginHandler::instance().save("test0.@", test_image_list1)); 
+	BOOST_REQUIRE(C2DImageIOPluginHandler::instance().save("test1.@", test_image_list2)); 
+
 	vector<string> filenames = {"test0.@","test1.@"}; 
 		
 	auto images = load_image_series(filenames); 
diff --git a/mia/2d/test_interpol.cc b/mia/2d/test_interpol.cc
index cfbe56f..47c5ced 100644
--- a/mia/2d/test_interpol.cc
+++ b/mia/2d/test_interpol.cc
@@ -126,11 +126,11 @@ struct FCompareImages: public TFilter<bool> {
 	}
 };
 
-void save(P2DImage image, const string& name)
+bool save(P2DImage image, const string& name)
 {
 	C2DImageIOPluginHandler::Instance::Data vlist;
 	vlist.push_back(image);
-	C2DImageIOPluginHandler::instance().save(name, vlist);
+	return C2DImageIOPluginHandler::instance().save(name, vlist); 
 }
 
 void test_deformadd()
@@ -169,10 +169,11 @@ void test_deformadd()
 	P2DImage result_direct = filter(FDeformer2D(A, *ipf), *image);
 
 	if (!filter_equal(FCompareImages(), *result_direct, *result_add)) {
-		save(image, "original.png");
-		save(im, "inter.png");
-		save(result_direct, "result_direct.png");
-		save(result_add, "result_add.png");
+		if (!save(image, "original.png") ||
+		    !save(im, "inter.png") || 
+		    !save(result_direct, "result_direct.png")||
+		    !save(result_add, "result_add.png"))
+			cverr() << "Couldn't write debug images\n"; 
 	}
 
 }
diff --git a/mia/2d/test_ppmatrix.cc b/mia/2d/test_ppmatrix.cc
index 90ec9e7..27238b5 100644
--- a/mia/2d/test_ppmatrix.cc
+++ b/mia/2d/test_ppmatrix.cc
@@ -78,26 +78,25 @@ struct TransformSplineFixtureConst: public TransformSplineFixtureFieldBase {
 	virtual float fx(float x, float y);
 	virtual float fy(float x, float y);
 private: 
-	float m_fx; 
-	float m_fy; 
+	C2DFVector m_f; 
 };
 
 void TransformSplineFixtureConst::prepare(int dsize, float range, EInterpolation type, float fx, float fy)
 {
-	m_fx = fx; 
-	m_fy = fy; 
+	m_f.x = fx; 
+	m_f.y = fy; 
 
 	init(dsize, range, type); 
 }
 
 float TransformSplineFixtureConst::fx(float , float )
 {
-	return m_fx; 
+	return m_f.x; 
 }
 
 float TransformSplineFixtureConst::fy(float , float )
 {
-	return m_fy; 
+	return m_f.y; 
 }
 
 
diff --git a/mia/2d/test_rigidregister.cc b/mia/2d/test_rigidregister.cc
index 509e50d..a1e9e03 100644
--- a/mia/2d/test_rigidregister.cc
+++ b/mia/2d/test_rigidregister.cc
@@ -35,36 +35,9 @@ using namespace mia;
 using namespace std; 
 namespace bfs=boost::filesystem;
 
-CSplineKernelTestPath init_splinekernel_path; 
+PrepareTestPluginPath g_prepare_pluginpath; 
 
-class PluginPathInitFixture {
-protected:
-	PluginPathInitFixture() {
-		CPathNameArray costsearchpath;
-		costsearchpath.push_back(bfs::path("cost"));
-		C2DImageCostPluginHandler::set_search_path(costsearchpath);
-
-		CPathNameArray transsearchpath;
-		transsearchpath.push_back(bfs::path("transform"));
-		C2DTransformCreatorHandler::set_search_path(transsearchpath);
-
-		CPathNameArray kernelsearchpath;
-		kernelsearchpath.push_back(bfs::path("..")/
-					   bfs::path("core")/bfs::path("spacialkernel"));
-		C1DSpacialKernelPluginHandler::set_search_path(kernelsearchpath);
-
-		CPathNameArray filterpath;
-		filterpath.push_back(bfs::path("filter"));
-		C2DFilterPluginHandler::set_search_path(filterpath);
-
-		CPathNameArray minimizerpath;
-		minimizerpath.push_back(bfs::path("../core/minimizer"));
-		CMinimizerPluginHandler::set_search_path(minimizerpath); 
-
-	}
-};
-
-class RigidRegisterFixture : public PluginPathInitFixture {
+class RigidRegisterFixture  {
 protected: 
 	RigidRegisterFixture(); 
 	void run(C2DTransformation& t, const string& minimizer_descr,  double accuracy); 
@@ -132,18 +105,6 @@ BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_nmsimplex, RigidRegisterFixture
 }
 
 
-BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_gd, RigidRegisterFixture )
-{
-	auto tr_creator = C2DTransformCreatorHandler::instance().produce("translate");
-	auto transformation = tr_creator->create(size); 
-	auto params = transformation->get_parameters(); 
-	params[0] = 1.0;
-	params[1] = 1.0;
-	transformation->set_parameters(params); 
-
-	run(*transformation, "nlopt:opt=ld-var1,xtolr=0.001,ftolr=0.001", 0.1); 
-}
-
 BOOST_FIXTURE_TEST_CASE( test_rigidreg_rigid_simplex, RigidRegisterFixture )
 {
 	auto tr_creator = C2DTransformCreatorHandler::instance().produce("rigid");
@@ -173,6 +134,21 @@ BOOST_FIXTURE_TEST_CASE( test_rigidreg_affine_simplex, RigidRegisterFixture )
 	run(*transformation, "gsl:opt=simplex,step=1.0,eps=0.0001", 1.0); 
 }
 
+#ifdef HAVE_NLOPT
+
+BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_gd, RigidRegisterFixture )
+{
+	auto tr_creator = C2DTransformCreatorHandler::instance().produce("translate");
+	auto transformation = tr_creator->create(size); 
+	auto params = transformation->get_parameters(); 
+	params[0] = 1.0;
+	params[1] = 1.0;
+	transformation->set_parameters(params); 
+
+	run(*transformation, "nlopt:opt=ld-var1,xtolr=0.001,ftolr=0.001", 0.1); 
+}
+#endif 
+
 #ifdef THIS_TEST_USES_THE_TRANSLATE_CODE_THAT_IS_NOT_WORKING
 BOOST_AUTO_TEST_CASE( test_rigidreg_affine_cost_gradient ) //, RigidRegisterFixture )
 {
diff --git a/mia/3d/camera.cc b/mia/3d/camera.cc
index 4418b60..af5ee80 100644
--- a/mia/3d/camera.cc
+++ b/mia/3d/camera.cc
@@ -22,8 +22,13 @@
 
 NS_MIA_BEGIN
 
+C3DCamera::C3DCamera():
+	m_zoom(1.0)
+{
+}	
+
 C3DCamera::C3DCamera(const C3DFVector& loc, const Quaternion& rot, float zoom):
-m_location(loc), 
+	m_location(loc), 
 	m_rotation(rot), 
 	m_zoom(zoom)
 {
diff --git a/mia/3d/camera.hh b/mia/3d/camera.hh
index 588bde9..a5f4a7b 100644
--- a/mia/3d/camera.hh
+++ b/mia/3d/camera.hh
@@ -33,7 +33,7 @@ NS_MIA_BEGIN
  */
 class EXPORT_3D C3DCamera {
 public: 
-	C3DCamera() = default;
+	C3DCamera(); 
 
 	/**
 	   Constructor 
diff --git a/mia/3d/cost/ngf.hh b/mia/3d/cost/ngf.hh
index 5f12852..e1b9328 100644
--- a/mia/3d/cost/ngf.hh
+++ b/mia/3d/cost/ngf.hh
@@ -75,11 +75,7 @@ private:
 	virtual void post_set_reference(const mia::C3DImage& ref); 
 
 	mia::C3DFVectorfield m_ng_ref;
-	bool m_jump_levels_valid;
-	float m_cost_baseline;
-
 	PEvaluator m_evaluator;
-	float m_intensity_scale;
 };
 
 class C3DNFGImageCostPlugin: public mia::C3DImageCostPlugin {
diff --git a/mia/3d/creator/sphere.cc b/mia/3d/creator/sphere.cc
index 9c19548..9a3fe74 100644
--- a/mia/3d/creator/sphere.cc
+++ b/mia/3d/creator/sphere.cc
@@ -103,7 +103,7 @@ P3DImage C3DSphereCreator::do_create(const C3DBounds& size) const
 				dx = pow(dx, m_p);
 
 				dx += dy;
-				*p =  (dx > l) ? 0 : *p = move_range<T,is_float>::apply(cos( dx / l * m_f * M_PI ));
+				*p =  (dx > l) ? 0 : move_range<T,is_float>::apply(cos( dx / l * m_f * M_PI ));
 			}
 		}
 	}
diff --git a/mia/3d/fifof/mlv.cc b/mia/3d/fifof/mlv.cc
index d69798d..65e5b4e 100644
--- a/mia/3d/fifof/mlv.cc
+++ b/mia/3d/fifof/mlv.cc
@@ -53,7 +53,8 @@ static void convert(InputIterator a, InputIterator e, OutputIterator o)
 C2DMLVnFifoFilter::C2DMLVnFifoFilter(size_t hwidth):
 	C2DImageFifoFilter(4 * hwidth + 1, 2 * hwidth + 1, 2 * hwidth),
 	m_hw(hwidth),
-	m_w(2 * hwidth + 1)
+	m_w(2 * hwidth + 1), 
+	m_buf_slice_size(0)
 {
 }
 
diff --git a/mia/3d/fifof/mlv.hh b/mia/3d/fifof/mlv.hh
index b9bf4b4..8873605 100644
--- a/mia/3d/fifof/mlv.hh
+++ b/mia/3d/fifof/mlv.hh
@@ -66,8 +66,6 @@ private:
 
 	size_t m_hw;
 	size_t m_w;
-	size_t m_start_slice;
-	size_t m_end_slice;
 	size_t m_buf_slice_size;
 };
 
diff --git a/mia/3d/fifof/regiongrow.cc b/mia/3d/fifof/regiongrow.cc
index 7ab719e..c51c7a5 100644
--- a/mia/3d/fifof/regiongrow.cc
+++ b/mia/3d/fifof/regiongrow.cc
@@ -41,7 +41,8 @@ C2DRegiongrowFifoFilter::C2DRegiongrowFifoFilter(const CProbabilityVector probma
 	m_low(low),
 	m_seed(seed),
 	m_class(cls),
-	m_depth(depth)
+	m_depth(depth), 
+	m_slice_emls(0)
 {
 	m_shape = C3DShapePluginHandler::instance().produce("6n");
 }
diff --git a/mia/3d/filter/mask.cc b/mia/3d/filter/mask.cc
index 213f96e..3cca00c 100644
--- a/mia/3d/filter/mask.cc
+++ b/mia/3d/filter/mask.cc
@@ -95,7 +95,8 @@ C3DMask::result_type C3DMask::operator () (const T3DImage<T>& data) const
 	P3DImage image = (*in_image_list)[0];
 
 	if (image->get_pixel_type() == it_bit) {
-		const C3DBitImage *mask = dynamic_cast<const C3DBitImage*>(image.get());
+		// use static cast because type is already tested. 
+		const C3DBitImage *mask = static_cast<const C3DBitImage*>(image.get());
 		C3DMaskDispatch m(mask, true);
 		return m(data);
 	} else {
diff --git a/mia/3d/filter/reorient.hh b/mia/3d/filter/reorient.hh
index 080c8da..23af4c0 100644
--- a/mia/3d/filter/reorient.hh
+++ b/mia/3d/filter/reorient.hh
@@ -51,7 +51,6 @@ private:
 	EOrientations get_strategy(mia::E3DImageOrientation old_orientation) const;
 	mia::E3DImageOrientation get_new_orientation(EOrientations strategy, mia::E3DImageOrientation old_orientation)const;
 	EOrientations m_strategy;
-	mia::E3DImageOrientation m_out_orientation;
 };
 
 
diff --git a/mia/3d/filter/scale.cc b/mia/3d/filter/scale.cc
index 6d0fe58..84aa9b5 100644
--- a/mia/3d/filter/scale.cc
+++ b/mia/3d/filter/scale.cc
@@ -25,6 +25,10 @@
 #include <mia/core/utils.hh>
 #include <mia/3d/filter/scale.hh>
 
+#include <mia/core/threadedmsg.hh>
+#include <tbb/parallel_for.h>
+#include <tbb/blocked_range.h>
+
 
 
 NS_BEGIN(scale_3dimage_filter)
@@ -36,9 +40,9 @@ namespace bfs= ::boost::filesystem;
 
 template <class T>
 C3DScale::result_type do_scale(const T3DImage<T>& src, const C3DBounds& target_size, 
-			       C1DScalar& scaler_x, 
-			       C1DScalar& scaler_y, 
-			       C1DScalar& scaler_z) 
+			       const C1DScalar& scaler_x, 
+			       const C1DScalar& scaler_y, 
+			       const C1DScalar& scaler_z) 
 {
 	T3DImage<T> *result = new T3DImage<T>(target_size, src);
 	
@@ -47,41 +51,54 @@ C3DScale::result_type do_scale(const T3DImage<T>& src, const C3DBounds& target_s
 
 // run x-scaling 
 	T3DImage<double> tmp(C3DBounds(target_size.x, src.get_size().y, src.get_size().z)); 
-	for (size_t z = 0; z < src.get_size().z; ++z) {
-		for (size_t y = 0; y < src.get_size().y; ++y) {
-			copy(src.begin_at(0,y,z), src.begin_at(0,y+1,z), scaler_x.input_begin()); 
-			scaler_x.run(); 
-			copy(scaler_x.output_begin(), scaler_x.output_end(), tmp.begin_at(0,y,z)); 
-		}
-	}
+
+	auto filter_x = [&src, &tmp, &scaler_x](const tbb::blocked_range<size_t>& range) {
+		vector<double> in_buffer(src.get_size().x); 
+		vector<double> out_buffer(tmp.get_size().x);
+		for (auto z = range.begin(); z != range.end(); ++z)
+			for (size_t y = 0; y < src.get_size().y; ++y) {
+				copy(src.begin_at(0,y,z), src.begin_at(0,y+1,z), in_buffer.begin()); 
+				scaler_x(in_buffer, out_buffer); 
+				copy(out_buffer.begin(), out_buffer.end(), tmp.begin_at(0,y,z));
+			}
+		
+	};
+	
+	parallel_for(tbb::blocked_range<size_t>(0, src.get_size().z, 1), filter_x); 
 
 	// run y-scaling 
 	T3DImage<double> tmp2(C3DBounds(target_size.x, target_size.y, src.get_size().z)); 
-	vector<double> in_buffer(src.get_size().y); 
-	vector<double> out_buffer(target_size.y);
-	for (size_t z = 0; z < src.get_size().z; ++z) {
-		for (size_t x = 0; x < target_size.x; ++x) {
-			tmp.get_data_line_y(x, z, in_buffer);
-			copy(in_buffer.begin(), in_buffer.end(), scaler_y.input_begin()); 
-			scaler_y.run(); 
-			copy(scaler_y.output_begin(), scaler_y.output_end(), out_buffer.begin());
-			tmp2.put_data_line_y(x, z, out_buffer);
-		}
-	}
-
-	// run z-scaling 
-	in_buffer.resize(src.get_size().z); 
-	vector<T> out_buffer_t(target_size.z);
-	for (size_t y = 0; y < target_size.y; ++y) {
-		for (size_t x = 0; x < target_size.x; ++x) {
-			tmp2.get_data_line_z(x, y, in_buffer);
-			copy(in_buffer.begin(), in_buffer.end(), scaler_z.input_begin()); 
-			scaler_z.run(); 
-			transform(scaler_z.output_begin(), scaler_z.output_end(), out_buffer_t.begin(), 
-				  [](double x){ return mia_round<T>(x); }); 
-			result->put_data_line_z(x, y, out_buffer_t);
-		}
-	}
+
+	auto filter_y = [&tmp, &tmp2, &scaler_y](const tbb::blocked_range<size_t>& range) {
+		vector<double> in_buffer(tmp.get_size().y); 
+		vector<double> out_buffer(tmp2.get_size().y);
+		for (auto z = range.begin(); z != range.end(); ++z)
+			for (size_t x = 0; x < tmp.get_size().x; ++x) {
+				tmp.get_data_line_y(x, z, in_buffer);
+				scaler_y(in_buffer, out_buffer); 
+				tmp2.put_data_line_y(x, z, out_buffer);
+			}
+		
+	};
+	parallel_for(tbb::blocked_range<size_t>(0, tmp.get_size().z, 1), filter_y); 
+
+	auto filter_z = [&tmp2, result, &scaler_z](const tbb::blocked_range<size_t>& range) {
+		vector<double> in_buffer(tmp2.get_size().z); 
+		vector<double> out_buffer(result->get_size().z);
+		vector<T> out_buffer_T(result->get_size().z);
+		for (auto y = range.begin(); y != range.end(); ++y)
+			for (size_t x = 0; x < tmp2.get_size().x; ++x) {
+				tmp2.get_data_line_z(x, y, in_buffer);
+				scaler_z(in_buffer, out_buffer); 
+				transform(out_buffer.begin(), out_buffer.end(), out_buffer_T.begin(), 
+					  [](double x){ return mia_round_clamped<T>(x);}); 
+				result->put_data_line_z(x, y, out_buffer_T);
+			}
+		
+	};
+
+	parallel_for(tbb::blocked_range<size_t>(0, tmp2.get_size().y, 1), filter_z); 
+
 	return C3DScale::result_type(result);	
 }
 			       
diff --git a/mia/3d/filter/test_mlv.cc b/mia/3d/filter/test_mlv.cc
index 151a9e5..fcba327 100644
--- a/mia/3d/filter/test_mlv.cc
+++ b/mia/3d/filter/test_mlv.cc
@@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE( test_mlv )
 								sum2 += val * val;
 								++n;
 							}
-					float m = mu(x,y,z) = sum / n;
+					float m = mu(x,y,z) = (n > 0) ? sum / n : 0.0f;
 					sigma(x,y,z) = (n > 1) ? (sum2 - n * m * m) / (n - 1) : 0.0f;
 				}
 
diff --git a/mia/3d/fullcost/taggedssd.hh b/mia/3d/fullcost/taggedssd.hh
index c6a3a3b..f45ec62 100644
--- a/mia/3d/fullcost/taggedssd.hh
+++ b/mia/3d/fullcost/taggedssd.hh
@@ -57,8 +57,6 @@ class EXPORT C3DTaggedSSDCost : public mia::C3DFullCost {
 	
 	mia::P3DImage m_src_scaled[3]; 
 	mia::P3DImage m_ref_scaled[3];
-
-	bool m_debug;
 }; 
 
 NS_END
diff --git a/mia/3d/fuzzyClusterSolverCG.cc b/mia/3d/fuzzyClusterSolverCG.cc
index 69b48ce..942a251 100644
--- a/mia/3d/fuzzyClusterSolverCG.cc
+++ b/mia/3d/fuzzyClusterSolverCG.cc
@@ -73,6 +73,13 @@ solve_sCG::solve_sCG (C3DFImage& w1, C3DFImage& f1, C3DFImage& gain_image, doubl
 	__scale2(new double[__count]),
 	__border(new bool[__count]),
 
+	__r1rho1(0.0), 
+	__r2rho2(0.0),
+	 __normr0(0.0),
+	__q(0.0), 
+	__e(0.0),
+	__sprod(0.0),
+
 	__min_res(m_res),
 	__relres(r_res)
 
diff --git a/mia/3d/image.cc b/mia/3d/image.cc
index 736ea8d..bc8af88 100644
--- a/mia/3d/image.cc
+++ b/mia/3d/image.cc
@@ -47,6 +47,7 @@ EPixelType C3DImage::get_pixel_type() const
 	return m_pixel_type;
 }
 
+
 E3DImageOrientation C3DImage::get_orientation() const
 {
 	const PAttribute orattr = get_attribute("orientation");
diff --git a/mia/3d/io/analyze.cc b/mia/3d/io/analyze.cc
index 02fe0b4..e06a0d7 100644
--- a/mia/3d/io/analyze.cc
+++ b/mia/3d/io/analyze.cc
@@ -160,7 +160,8 @@ extern "C" EXPORT CPluginBase *get_plugin_interface()
 
 CAnalyze3DImageIOPlugin::CAnalyze3DImageIOPlugin():
 	C3DImageIOPlugin("analyze"),
-	m_type_table(analyze_type_table)
+	m_type_table(analyze_type_table), 
+	m_swap_endian(false)
 {
 //	add_supported_type(it_bit);
 	add_supported_type(it_ubyte);
@@ -443,6 +444,17 @@ CAnalyze3DImageIOPlugin::PData CAnalyze3DImageIOPlugin::do_load(const string&  f
 	// create output list
 	PData result(new C3DImageVector());
 
+	int voffset = static_cast<int>(hdr.dime.vox_offset); 
+
+
+	// Coverty will complain about an untrusted value. 
+	// This is no problem, because if voffset is off the scale, the 
+	// data reading will fail and the plug-in will throw. 
+	if (voffset > 0) 
+		if (!fseek(data_file, voffset, SEEK_CUR)) 
+			throw create_exception<runtime_error>("Analyze: unable seek in data file '", 
+							      data_file_name, "':", strerror(errno) );
+	
         // read data
 	while (num_img > 0) {
 		--num_img;
@@ -462,10 +474,10 @@ CAnalyze3DImageIOPlugin::PData CAnalyze3DImageIOPlugin::do_load(const string&  f
 			unflipped = true;
 			orientation = ior_unknown;
 		}
-		if (hdr.dime.vox_offset > 0) {
-			vector<char> junk(hdr.dime.vox_offset); 
-			if (fread(&junk[0], 1, hdr.dime.vox_offset, data_file) != hdr.dime.vox_offset) 
-				throw runtime_error(string("Analyze: unable to read from:") + data_file_name);  
+		if (voffset < 0) {
+			if (!fseek(data_file, -voffset, SEEK_CUR)) 
+				throw create_exception<runtime_error>("Analyze: unable seek in data file '", 
+							      data_file_name, "':", strerror(errno) );
 		}
 		C3DImage *img = unflipped ?
 			read_image<false>(size, hdr.dime.datatype , data_file)
diff --git a/mia/3d/io/inria.cc b/mia/3d/io/inria.cc
index 37f2ff4..ea6af7e 100644
--- a/mia/3d/io/inria.cc
+++ b/mia/3d/io/inria.cc
@@ -96,6 +96,7 @@ CInria3DImageIOPlugin::CInria3DImageIOPlugin():
 	add_supported_type(it_float);
 	add_supported_type(it_double);
 	add_suffix(".inr");
+	add_suffix(".INR");
 }
 
 
diff --git a/mia/3d/io/vff.cc b/mia/3d/io/vff.cc
index da91390..432dfba 100644
--- a/mia/3d/io/vff.cc
+++ b/mia/3d/io/vff.cc
@@ -52,6 +52,13 @@ struct SHeader {
 	float m_max;
 	float m_elementsize;
 	C3DFVector m_spacing;
+	SHeader():m_valid(false), 
+		  m_pixel_type(it_unknown), 
+		  m_rank(0), 
+		  m_min(0), 
+		  m_max(0), 
+		  m_elementsize(0){
+	}
 };
 
 typedef bool (*FDecode)(istream& is, SHeader& header);
@@ -173,6 +180,7 @@ CVFF3DImageIO::CVFF3DImageIO():
 	add_supported_type(it_sshort);
 	add_supported_type(it_ubyte);
 	add_suffix(".vff");
+	add_suffix(".VFF");
 }
 
 
@@ -263,8 +271,8 @@ void handle_endian(Iterator b, Iterator e)
 			++b;
 		}
 		break;
-		cvdebug() << "Endian correct 64 bit data\n";
 	case 8:
+		cvdebug() << "Endian correct 64 bit data\n";
 		while (b != e) {
 
 			shuffle s;
@@ -322,7 +330,8 @@ CVFF3DImageIO::PData CVFF3DImageIO::do_load(string const&  filename)const
 			*end = 0;
 
 			if (!store_info(buffer, split, header)) {
-				throw invalid_argument(string("vff-load:Read component '") + string(split)  + string("' failed"));
+				throw invalid_argument(string("vff-load:Read component '") 
+						       + string(split)  + string("' failed"));
 			}
 		}else{
 			if (buffer[0] != 0xC)
@@ -356,7 +365,7 @@ CVFF3DImageIO::PData CVFF3DImageIO::do_load(string const&  filename)const
 		}
 	}break;
 	default:
-		assert(!"input format not implemented");
+		throw invalid_argument(string("vff-load: input format not implemented"));
 	}
 
 	if (result->size() > 0)
diff --git a/mia/3d/landmark.cc b/mia/3d/landmark.cc
index 6d7f96d..11d5cc0 100644
--- a/mia/3d/landmark.cc
+++ b/mia/3d/landmark.cc
@@ -28,14 +28,16 @@ using namespace std;
 
 C3DLandmark::C3DLandmark(const string& _name):
 	m_name(_name), 
-	m_has_location(false) 
+	m_has_location(false), 
+	m_isovalue(0.0)
 {
 }
 
 C3DLandmark::C3DLandmark(const std::string& name, const C3DFVector& location):
 	m_name(name),
 	m_has_location(true), 
-	m_location(location)
+	m_location(location), 
+	m_isovalue(0.0)
 {
 }
 
diff --git a/mia/3d/reg3d/navier.cc b/mia/3d/reg3d/navier.cc
index 8553ee1..b0755bf 100644
--- a/mia/3d/reg3d/navier.cc
+++ b/mia/3d/reg3d/navier.cc
@@ -48,7 +48,7 @@ private:
 	float  solve_at(const C3DFVector& b, C3DFVectorfield::iterator& x)const;
 	float m_mu;
 	float m_lambda;
-	float m_a1,m_a, m_b, m_c, m_a_b, m_b_4;
+	float m_a,  m_c, m_a_b, m_b_4;
 	float m_omega;
 	float m_epsilon;
 	size_t m_max_iter;
@@ -62,7 +62,9 @@ C3DNavierRegModel::C3DNavierRegModel(float mu, float lambda, size_t maxiter, flo
 	m_lambda(lambda),
 	m_omega(omega),
 	m_epsilon(epsilon),
-	m_max_iter(maxiter)
+	m_max_iter(maxiter), 
+	m_dx(0), 
+	m_dxy(0)
 {
 	float a = mu;
 	float b = lambda + mu;
diff --git a/mia/3d/reg3d/naviera.cc b/mia/3d/reg3d/naviera.cc
index 3302749..e85f6ef 100644
--- a/mia/3d/reg3d/naviera.cc
+++ b/mia/3d/reg3d/naviera.cc
@@ -64,7 +64,7 @@ private:
 	PRIVATE float  solve_at(const C3DFVector& b, C3DFVectorfield::iterator& x)const;
 	float m_mu;
 	float m_lambda;
-	float m_a1,m_a, m_b, m_c, m_a_b, m_b_4;
+	float m_a, m_c, m_a_b, m_b_4;
 //	float m_omega;
 	float m_epsilon;
 	size_t m_max_iter;
@@ -85,6 +85,8 @@ C3DNavierRegModel::C3DNavierRegModel(float mu, float lambda, size_t maxiter,  fl
 	m_b_4 = 0.25 * b * m_c;
 	m_a_b = ( a + b ) * m_c;
 	m_a = a * m_c;
+	m_dx = 0; 
+	m_dxy = 0; 
 
 	cvdebug() << "initialise model with mu=" << mu << " lambda=" << lambda << "\n";
 }
diff --git a/mia/3d/reg3d/navierasse.cc b/mia/3d/reg3d/navierasse.cc
index 57cc93e..f460ccb 100644
--- a/mia/3d/reg3d/navierasse.cc
+++ b/mia/3d/reg3d/navierasse.cc
@@ -73,7 +73,7 @@ private:
 //	float  solve_at(const C3DFVector& b, v4sf *x, const v4sf *param)const;
 	float m_mu;
 	float m_lambda;
-	float m_a1,m_a, m_b, m_c, m_a_b, m_b_4;
+	float m_a, m_c, m_a_b, m_b_4;
 //	float m_omega;
 	float m_epsilon;
 	size_t m_max_iter;
diff --git a/mia/3d/test_3d.cc b/mia/3d/test_3d.cc
index fbeb7f4..0115a7a 100644
--- a/mia/3d/test_3d.cc
+++ b/mia/3d/test_3d.cc
@@ -52,9 +52,12 @@ bool init_unit_test_suite( )
 }
 
 int BOOST_TEST_CALL_DECL
-main( int argc, char* argv[] )
+do_main( int argc, char* argv[] )
 {
 	if (CCmdOptionList(g_general_help).parse(argc, (const char**)argv, "boost-test-option") != CCmdOptionList::hr_no) 
 		return 0; 
 	return ::boost::unit_test::unit_test_main( &init_unit_test_suite, argc, argv );
 }
+
+#include <mia/internal/main.hh>
+MIA_MAIN(do_main);
diff --git a/mia/3d/test_imageio.cc b/mia/3d/test_imageio.cc
index cc71d7f..529f490 100644
--- a/mia/3d/test_imageio.cc
+++ b/mia/3d/test_imageio.cc
@@ -81,7 +81,7 @@ bool init_unit_test_suite( )
 
 NS_MIA_USE; 
 int BOOST_TEST_CALL_DECL
-main( int argc, char* argv[] )
+do_main( int argc, char* argv[] )
 {
 
 #ifdef WIN32
@@ -94,3 +94,6 @@ main( int argc, char* argv[] )
 	return ::boost::unit_test::unit_test_main( &init_unit_test_suite, argc, argv );
 }
 
+
+#include <mia/internal/main.hh>
+MIA_MAIN(do_main);
diff --git a/mia/3d/test_ppmatrix.cc b/mia/3d/test_ppmatrix.cc
index 54593a1..e000427 100644
--- a/mia/3d/test_ppmatrix.cc
+++ b/mia/3d/test_ppmatrix.cc
@@ -26,10 +26,12 @@ NS_MIA_USE;
 CSplineKernelTestPath splinekernel_init_path; 
 
 struct TransformSplineFixtureFieldBase {
-	TransformSplineFixtureFieldBase()
-	{
-
-	}
+	TransformSplineFixtureFieldBase():
+		range(1.0), 
+		graddiv2sum(0.0)
+		{
+		}
+	
 	void init(int dsize, double r, EInterpolation type) {
 		ipf.reset(create_3dinterpolation_factory(type, bc_mirror_on_bounds));
 		size = C3DBounds(2 * dsize + 1,2 * dsize + 1,2 * dsize + 1);
@@ -326,7 +328,8 @@ BOOST_FIXTURE_TEST_CASE( test_mix_bspline4_10_4_grad, TransformSplineFixtureMixe
 
 
 struct TransformSplineFixtureFieldNonuniform {
-	TransformSplineFixtureFieldNonuniform()
+	TransformSplineFixtureFieldNonuniform():
+		range(1.0)
 	{
 
 	}
diff --git a/mia/3d/test_rigidregister.cc b/mia/3d/test_rigidregister.cc
index fe97aa8..7ea6547 100644
--- a/mia/3d/test_rigidregister.cc
+++ b/mia/3d/test_rigidregister.cc
@@ -36,37 +36,9 @@ NS_MIA_USE
 using namespace std; 
 namespace bfs=boost::filesystem;
 
-CSplineKernelTestPath splinekernel_init_path; 
+PrepareTestPluginPath g_prepare_pluginpath; 
 
-class PluginPathInitFixture {
-protected:
-	PluginPathInitFixture() {
-		CPathNameArray costsearchpath;
-		costsearchpath.push_back(bfs::path("cost"));
-		C3DImageCostPluginHandler::set_search_path(costsearchpath);
-
-		CPathNameArray transsearchpath;
-		transsearchpath.push_back(bfs::path("transform"));
-		C3DTransformCreatorHandler::set_search_path(transsearchpath);
-
-		CPathNameArray kernelsearchpath;
-		kernelsearchpath.push_back(bfs::path("..")/
-					   bfs::path("core")/bfs::path("spacialkernel"));
-		C1DSpacialKernelPluginHandler::set_search_path(kernelsearchpath);
-
-		CPathNameArray filterpath;
-		filterpath.push_back(bfs::path("filter"));
-		C3DFilterPluginHandler::set_search_path(filterpath);
-		
-		CPathNameArray minimizerpath;
-		minimizerpath.push_back(bfs::path("../core/minimizer"));
-		CMinimizerPluginHandler::set_search_path(minimizerpath); 
-
-
-	}
-};
-
-class RigidRegisterFixture : public PluginPathInitFixture {
+class RigidRegisterFixture {
 protected: 
 	RigidRegisterFixture(); 
 	void run(C3DTransformation& t, const std::string& minimizer_descr,  double accuracy); 
@@ -166,19 +138,6 @@ BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_nmsimplex, RigidRegisterFixture
 }
 
 
-BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_gd, RigidRegisterFixture )
-{
-	auto tr_creator = C3DTransformCreatorHandler::instance().produce("translate");
-	auto transformation = tr_creator->create(size); 
-	auto params = transformation->get_parameters(); 
-	params[0] = 1.0;
-	params[1] = 1.0;
-	params[2] = 2.0;
-	transformation->set_parameters(params); 
-
-	run(*transformation, "nlopt:opt=ld-var1,xtolr=0.01,ftolr=0.01", 0.8); 
-}
-
 BOOST_FIXTURE_TEST_CASE( test_rigid_simplex, RigidRegisterFixture )
 {
 	auto tr_creator = C3DTransformCreatorHandler::instance().produce("rigid");
@@ -196,6 +155,20 @@ BOOST_FIXTURE_TEST_CASE( test_rigid_simplex, RigidRegisterFixture )
 	run(*transformation, "gsl:opt=simplex,step=1.0", 16.0); 
 }
 
+#ifdef HAVE_NLOPT
+
+BOOST_FIXTURE_TEST_CASE( test_rigidreg_translate_gd, RigidRegisterFixture )
+{
+	auto tr_creator = C3DTransformCreatorHandler::instance().produce("translate");
+	auto transformation = tr_creator->create(size); 
+	auto params = transformation->get_parameters(); 
+	params[0] = 1.0;
+	params[1] = 1.0;
+	params[2] = 2.0;
+	transformation->set_parameters(params); 
+
+	run(*transformation, "nlopt:opt=ld-var1,xtolr=0.01,ftolr=0.01", 0.8); 
+}
 
 BOOST_FIXTURE_TEST_CASE( test_rigid_ld_lbfgs, RigidRegisterFixture )
 {
@@ -214,6 +187,8 @@ BOOST_FIXTURE_TEST_CASE( test_rigid_ld_lbfgs, RigidRegisterFixture )
 	run(*transformation, "nlopt:opt=ld-lbfgs,xtolr=0.001,ftolr=0.001", 4.0); 
 }
 
+#endif // HAVE_NLOPT
+
 #if 0 
 // the problem with tese tests is, that the images to be registered are 
 // too ambigious, so that more then just one affine transformation 
diff --git a/mia/3d/transform.cc b/mia/3d/transform.cc
index 44f6e24..6d7da39 100644
--- a/mia/3d/transform.cc
+++ b/mia/3d/transform.cc
@@ -30,7 +30,8 @@
 NS_MIA_BEGIN
 
 C3DTransformation::C3DTransformation(const C3DInterpolatorFactory& ipf):
-	Transformation<C3DImage, C3DInterpolatorFactory>(ipf)
+	Transformation<C3DImage, C3DInterpolatorFactory>(ipf), 
+	m_debug(false)
 {
 
 }
diff --git a/mia/3d/transform/test_spline.cc b/mia/3d/transform/test_spline.cc
index 1ff3acc..c6015ae 100644
--- a/mia/3d/transform/test_spline.cc
+++ b/mia/3d/transform/test_spline.cc
@@ -1037,7 +1037,9 @@ double Cost3DMock::ref_value(const C3DFVector& x) const
 /////////////////////////////////////
 struct TransformSplineFixtureFieldBase2 : public ipfFixture{
 	TransformSplineFixtureFieldBase2():
-		kernel(produce_spline_kernel("bspline:d=4"))
+		kernel(produce_spline_kernel("bspline:d=4")), 
+		range(1.0), 
+		graddiv2sum(0.0)
 	{
 
 	}
diff --git a/mia/core/CMakeLists.txt b/mia/core/CMakeLists.txt
index 1a26cc1..a3befe6 100644
--- a/mia/core/CMakeLists.txt
+++ b/mia/core/CMakeLists.txt
@@ -296,7 +296,6 @@ NEW_TEST(iohandler miacore)
 NEW_TEST(kmeans miacore)
 NEW_TEST(labelmap miacore)
 NEW_TEST(meanvar  miacore)
-NEW_TEST(minimizer miacore)
 NEW_TEST(productcache  miacore)
 NEW_TEST(property_flags  miacore)
 NEW_TEST(scaler1d miacore)
diff --git a/mia/core/attributes.hh b/mia/core/attributes.hh
index 5ce5ec8..bcbe088 100644
--- a/mia/core/attributes.hh
+++ b/mia/core/attributes.hh
@@ -539,8 +539,12 @@ struct dispatch_attr_string<std::vector<T> > {
 	static std::vector<T> string2val(const std::string& str) {
 		size_t s;
 		std::istringstream svalue(str);
+		std::vector<T> v; 
 		svalue >> s;
-		std::vector<T> v(s);
+		if (s > v.max_size())
+			throw create_exception<std::runtime_error>("string2val: try to create a vector of size ", 
+								   s, " but support only size ", v.max_size()); 
+		v.resize(s);
 		for (size_t i = 0; i < s; ++i)
 			svalue >> v[i];
 		if (svalue.fail()) {
@@ -625,13 +629,9 @@ template <>
 struct dispatch_attr_string<CAttributeMap> {
 	static std::string val2string(const CAttributeMap& /*value*/) {
 		throw std::invalid_argument("Conversion of a CAttributeMap to a string not implemented");
-		// avoid warnings ...
-		return std::string("");
 	}
 	static CAttributeMap string2val(const std::string& /*str*/) {
 		throw std::invalid_argument("Conversion of a string to a CAttributeMap not implemented");
-                // avoid warnings ...
-		return CAttributeMap();
 	}
 };
 
diff --git a/mia/core/cmdlineparser.cc b/mia/core/cmdlineparser.cc
index 39339c4..8e2d345 100644
--- a/mia/core/cmdlineparser.cc
+++ b/mia/core/cmdlineparser.cc
@@ -137,12 +137,14 @@ string CCmdOptionListData::set_description_value(EProgramDescriptionEntry entry,
 	else {
 		auto ed = g_DescriptionEntryNames.find(entry); 
 		assert(ed != g_DescriptionEntryNames.end()); 
-		if (!default_value) 
+		if (!default_value) {
 			cvwarn() << "Description value '" <<  ed->second << "' not set\n"; 
-		else 
+			return string(""); 
+		} else {
 			cvdebug() << "Description value '" <<  ed->second 
 				  << "' not set, using default '" << default_value << "'\n"; 
-		return string(default_value); 
+			return string(default_value); 
+		}
 	}
 }
 
diff --git a/mia/core/fftslopeclassifier.cc b/mia/core/fftslopeclassifier.cc
index e2cfe0b..77f28d4 100644
--- a/mia/core/fftslopeclassifier.cc
+++ b/mia/core/fftslopeclassifier.cc
@@ -168,7 +168,8 @@ CFFTSlopeClassifierImpl::CFFTSlopeClassifierImpl():
 	LV_idx(-1), 
 	Perfusion_idx(-1), 
 	Baseline_idx(-1), 
-	max_freq_energy(0)
+	max_freq_energy(0), 
+	max_slope_length_diff(0)
 {
 }
 
@@ -176,8 +177,8 @@ CFFTSlopeClassifierImpl::CFFTSlopeClassifierImpl():
 CFFTSlopeClassifierImpl::CFFTSlopeClassifierImpl(const CFFTSlopeClassifier::Columns& series, float breath_rate, bool /*mean_stripped*/):
 	Perfusion_idx(-1),
 	Baseline_idx(-1), 
-	max_freq_energy(0.0)
-
+	max_freq_energy(0.0), 
+	max_slope_length_diff(0)
 {
 	size_t n = series.size();
 	vector<statmap> stats(n);
diff --git a/mia/core/fifofilter.cxx b/mia/core/fifofilter.cxx
index 6336921..5583ae3 100644
--- a/mia/core/fifofilter.cxx
+++ b/mia/core/fifofilter.cxx
@@ -35,6 +35,8 @@ TFifoFilter<T>::TFifoFilter(size_t filter_width, size_t min_fill, size_t read_st
 	m_min_fill(min_fill + read_start), 
 	m_read_start(read_start), 
 	m_fill(0), 
+	m_start_slice(0), 
+	m_end_slice(0), 
 	m_initialized(false)
 {
 }
diff --git a/mia/core/fixedwidthoutput.cc b/mia/core/fixedwidthoutput.cc
index a7fa897..80b8129 100644
--- a/mia/core/fixedwidthoutput.cc
+++ b/mia/core/fixedwidthoutput.cc
@@ -102,7 +102,7 @@ void CFixedWidthOutput::write(const std::string& text)
 			size_t endpos = m_pos; 
 			
 			// search end of next word 
-			while (*hs != *es && !isspace(*hs)) {
+			while (hs != es && !isspace(*hs)) {
 				++endpos;
 				++hs; 
 			}
diff --git a/mia/core/handler.cxx b/mia/core/handler.cxx
index 6d0234d..d1472ef 100644
--- a/mia/core/handler.cxx
+++ b/mia/core/handler.cxx
@@ -265,11 +265,11 @@ typename TPluginHandler<I>::Interface *TPluginHandler<I>::plugin(const char *plu
 	auto p = m_plugins.find(plugin); 
 	if (p == m_plugins.end()) {
 		std::stringstream msg; 
-		msg << "Plugin '" << plugin << "' not found in '" 
-		    << I::PlugType::type_descr << "/" <<  I::PlugData::data_descr << "'\n"
+		cvdebug() << "Plugin '" << plugin << "' not found in '" 
+		    <<  I::PlugData::data_descr << "/" << I::PlugType::type_descr << "'\n"
 		    << " With search path\n"
 		    << "    '" << get_plugin_root(); 
-		throw std::invalid_argument(msg.str()); 
+		return nullptr; 
 	}
 	return p->second; 
 }
diff --git a/mia/core/histogram.hh b/mia/core/histogram.hh
index f7855cd..e9f3951 100644
--- a/mia/core/histogram.hh
+++ b/mia/core/histogram.hh
@@ -361,7 +361,7 @@ typename Feeder::value_type THistogram<Feeder>::median() const
 	while ( sum < n_2 ) 
 		sum +=  m_histogram[k++]; 
 
-	return m_feeder.value(k-1); 
+	return m_feeder.value(k > 0 ? k-1 : k); 
 }
 
 template <typename Feeder> 
diff --git a/mia/core/history.cc b/mia/core/history.cc
index 30843a9..7638454 100644
--- a/mia/core/history.cc
+++ b/mia/core/history.cc
@@ -38,7 +38,8 @@ void CHistory::append(const string& me, const string& version, const CCmdOptionL
 	CHistoryRecord record = options.get_values();
 	record["+PROGRAM"] = me;
 	record["+VERSION"] = version;
-	record["+USER"] = string(getenv("USER"));
+	const char *user = getenv("USER"); 
+	record["+USER"] = string(user ? user : "unknown");
 	record["+LIBMIA_VERSION"] = PACKAGE_VERSION;
 	record["+LIBMIA_REVISION"] = get_revision();
 	time_t t = time(NULL);
diff --git a/mia/core/iohandler.cxx b/mia/core/iohandler.cxx
index 35cbbdb..3ea832c 100644
--- a/mia/core/iohandler.cxx
+++ b/mia/core/iohandler.cxx
@@ -97,7 +97,18 @@ std::string TIOPluginHandler<I>::get_preferred_suffix(const std::string& type) c
 	TRACE_FUNCTION; 
 	auto plugin = this->plugin(type.c_str());
 	if ( !plugin ) {
-		throw create_exception<std::invalid_argument>("Plug-in '", type, "' not available"); 
+		// this may be a file suffix in itself, check if theres is a plug-in 
+		
+		const auto* iface = preferred_plugin_ptr(type); 
+		if (!iface) {
+			throw create_exception<std::runtime_error>("'", type, "' neither constitues an available plug-in "
+								      "nor a known file suffix, impossible to deduct a proper file suffix.", 
+								      "Available plug-ins are '", this->get_plugin_names(), "' with known file suffixes '", 
+								      get_supported_suffixes()); 
+		}
+		// if a valid suffix was given don't change it.
+		return type; 
+		
 	}
 	return plugin->get_preferred_suffix(); 
 }
diff --git a/mia/core/minimizer/CMakeLists.txt b/mia/core/minimizer/CMakeLists.txt
index 20b8906..9888a85 100644
--- a/mia/core/minimizer/CMakeLists.txt
+++ b/mia/core/minimizer/CMakeLists.txt
@@ -22,23 +22,4 @@ PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" gsl "${GSLOPTLIBS}")
 SET(NEEDED_LIBS miacore "${NEEDED_LIBS}")
 PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" gdsq "${NEEDED_LIBS}")
 
-OPTION(WITH_NLOPT "enable support for nlopt nonlinear optimizers" ${SEARCH_LIBS_DEFAULT})
-IF(WITH_NLOPT)
-
-  IF(NOT NLOPT_LIBRARIES) 
-    PKG_CHECK_MODULES(NLOPT nlopt)
-  ENDIF(NOT NLOPT_LIBRARIES) 
-
-  IF(NLOPT_LIBRARIES) 
-    SET(NLOPTLIBS ${MIACORE} ${NLOPT_LIBRARIES})
-    PLUGIN_WITH_TEST_AND_PREFIX2("minimizer" "singlecost" nlopt "${NLOPTLIBS}")
-  ELSE (NLOPT_LIBRARIES)
-    IF(STRICT_DEPENDECIES)
-      MESSAGE(ERROR "Requested library nlopt not found and STRICT_DEPENDECIES given")
-    ENDIF(STRICT_DEPENDECIES)
-  ENDIF(NLOPT_LIBRARIES)
-ENDIF(WITH_NLOPT)
-
-
-
 
diff --git a/mia/core/minimizer/gsl.cc b/mia/core/minimizer/gsl.cc
index f1ac991..5686706 100644
--- a/mia/core/minimizer/gsl.cc
+++ b/mia/core/minimizer/gsl.cc
@@ -51,6 +51,12 @@ CGSLFDFMinimizer::CGSLFDFMinimizer(const gsl_multimin_fdfminimizer_type *ot,
 	m_start_step(start_step)
 {
 	add(property_gradient); 
+
+	m_func.n = 0; 
+	m_func.f = nullptr; 
+	m_func.df = nullptr; 
+	m_func.fdf = nullptr; 
+	m_func.params = nullptr;
 	
 }
 
@@ -159,6 +165,9 @@ CGSLFMinimizer::CGSLFMinimizer(const gsl_multimin_fminimizer_type *ot,
 	m_start_step(start_step), 
 	m_step_init(NULL)
 {
+	m_func.n = 0; 
+	m_func.f = nullptr; 
+	m_func.params = nullptr;
 }
 
 CGSLFMinimizer::~CGSLFMinimizer()
diff --git a/mia/core/noise/gauss.cc b/mia/core/noise/gauss.cc
index 52f3acc..c640eb8 100644
--- a/mia/core/noise/gauss.cc
+++ b/mia/core/noise/gauss.cc
@@ -70,7 +70,8 @@ CGaussNoiseGenerator::CGaussNoiseGenerator(unsigned int seed, double mu, double
 	CNoiseGenerator(seed),
 	m_mu(mu),
 	m_sigma( sigma ),
-	m_use_last(false)
+	m_use_last(false), 
+	m_y2(0.0)
 {
 }
 
diff --git a/mia/core/parameter.hh b/mia/core/parameter.hh
index 53e3922..69962a7 100644
--- a/mia/core/parameter.hh
+++ b/mia/core/parameter.hh
@@ -237,7 +237,7 @@ public:
 	   \param descr a description of the parameter
 	   \param required set if this parameter must be set by the end user 
 	 */
-	CDictParameter(T& value, const TDictMap<T> dict, const char *descr, bool required = false);
+	CDictParameter(T& value, const TDictMap<T>& dict, const char *descr, bool required = false);
 protected:
 	/**
 	   the implementation of the description-function
@@ -511,7 +511,7 @@ struct __dispatch_param_translate<const char *> {
 /// @endcond 
 
 template <typename T>
-CDictParameter<T>::CDictParameter(T& value, const TDictMap<T> dict, const char *descr, bool required):
+CDictParameter<T>::CDictParameter(T& value, const TDictMap<T>& dict, const char *descr, bool required):
 	CParameter("dict", required, descr),
 	m_value(value),
 	m_default_value(value),
diff --git a/mia/core/plugin_base.cc b/mia/core/plugin_base.cc
index 9b90a1f..e8e8dcf 100644
--- a/mia/core/plugin_base.cc
+++ b/mia/core/plugin_base.cc
@@ -172,6 +172,18 @@ PPluginModule CPluginBase::get_module() const
 	return m_module;
 }
 
+const char *g_plugin_root = nullptr; 
+
+PrepareTestPluginPath::PrepareTestPluginPath()
+{
+	g_plugin_root = PLUGIN_TEST_ROOT "/" PLUGIN_INSTALL_PATH; 
+}
+
+PrepareTestPluginPath::~PrepareTestPluginPath()
+{
+	g_plugin_root = nullptr; 
+}
+
 #ifdef WIN32
 EXPORT_CORE const string get_plugin_root()
 {
@@ -212,8 +224,15 @@ EXPORT_CORE const string get_plugin_root()
 	return result;
 }
 #else
+
+
+
 const string EXPORT_CORE get_plugin_root()
 {
+	// this is the override for tests
+	if (g_plugin_root) 
+		return string(g_plugin_root); 
+
 	// fixme: this should also go into some config file
 	char *plugin_root = getenv("MIA_PLUGIN_TESTPATH"); 
 	if (plugin_root) 
diff --git a/mia/core/plugin_base.hh b/mia/core/plugin_base.hh
index 682692b..08f9359 100644
--- a/mia/core/plugin_base.hh
+++ b/mia/core/plugin_base.hh
@@ -41,6 +41,21 @@ NS_MIA_BEGIN
 /// standard string to print out help in the factory plug-in handler 
 EXPORT_CORE extern const std::string plugin_help;
 
+
+/**
+   This class sets the plug-in search path for 
+   to the build tree based location. It should only instanciated 
+   for running unit-like tests.
+   Calling the destructor will reset the plug-in search path estimation 
+   to its normal behaviour. 
+*/
+
+struct EXPORT_CORE PrepareTestPluginPath {
+	PrepareTestPluginPath(); 
+	~PrepareTestPluginPath(); 
+
+}; 
+
 /**
     \ingroup plugin
    \brief The base class for all plug-ins.
diff --git a/mia/core/slopestatistics.cc b/mia/core/slopestatistics.cc
index c35077c..bc95b64 100644
--- a/mia/core/slopestatistics.cc
+++ b/mia/core/slopestatistics.cc
@@ -146,12 +146,22 @@ float CSlopeStatistics::get_energy() const
 CSlopeStatisticsImpl::CSlopeStatisticsImpl(const vector<float>& series, int index):
 	m_series(series),
 	m_curve_length_valid(false),
+	m_curve_length(0.0), 
 	m_range_valid(false),
 	m_perfusion_peak_valid(false),
+	m_range(0.0), 
+	m_mean_freq(0.0), 
+	m_energy(0.0), 
 	m_mean_freq_valid(false), 
 	m_start_movement(-1), 
 	m_gradient_peak_valid(false), 
 	m_wt_valid(false), 
+	m_wt_peak_coefficient(0),
+	m_wt_mean_wt_level(0),
+	m_wt_energy(0),
+	m_energy_pos(CSlopeStatistics::ecp_none), 
+	m_energy_time_mean(0), 
+	m_maximum_gradient_from_zero(0), 
 	m_index(index)
 {
 }
@@ -479,6 +489,10 @@ void CSlopeStatisticsImpl::evaluate_wt() const
 		  [](double x) { return fabs(x);}); 
 	
 	int levels = log2(wt_transformed.size()); 
+	if (levels < 2) 
+		throw create_exception<invalid_argument>("CSlopeStatistics::evaluate_wt: Series size", wt_transformed.size(), 
+							 "too short for a sensible evaluation"); 
+
 	int ncoeffs = 1; 
 	m_wt_peak_coefficient = 0.0; 
 	auto c = wt_transformed.begin() + 1; 
diff --git a/mia/core/spacialkernel/gauss.cc b/mia/core/spacialkernel/gauss.cc
index b59368a..5f64a26 100644
--- a/mia/core/spacialkernel/gauss.cc
+++ b/mia/core/spacialkernel/gauss.cc
@@ -117,8 +117,9 @@ std::vector<double> C1DGaussFilterKernel::do_apply(const std::vector<double>& da
 	}
 
 	// filter at right boundary
-	for (int i = 0; i < get_fsize() && pos >= 0 && trgt != data.end(); ++i, --pos, ++trgt) {
-
+	for (int i = 0; i < get_fsize() && pos >= 0 && trgt != result.end() &&
+		     start != data.end();   ++i, --pos, ++trgt, ++start) {
+		
 		C1DFoldingKernel::const_iterator  ik = begin();
 		double  ht = 0.0;
 
@@ -132,8 +133,6 @@ std::vector<double> C1DGaussFilterKernel::do_apply(const std::vector<double>& da
 		}
 
 		*trgt = ht;
-
-		++start;
 	}
 	return result;
 }
diff --git a/mia/core/splineparzenmi.cc b/mia/core/splineparzenmi.cc
index 9280a1d..218203b 100644
--- a/mia/core/splineparzenmi.cc
+++ b/mia/core/splineparzenmi.cc
@@ -47,10 +47,12 @@ CSplineParzenMI::CSplineParzenMI(size_t rbins, PSplineKernel rkernel,
 	m_ref_kernel(rkernel), 
 	m_ref_border((rkernel->size() - 1) >> 1), 
 	m_ref_real_bins(m_ref_bins + 2 * m_ref_border), 
+        m_ref_scale(1.0), 
 	m_mov_bins(mbins), 
 	m_mov_kernel(mkernel), 
 	m_mov_border((mkernel->size() - 1) >> 1), 
 	m_mov_real_bins(m_mov_bins + 2 * m_mov_border), 
+        m_mov_scale(1.0), 
 	m_joined_histogram(m_ref_real_bins * m_mov_real_bins + 1/*(1)*/, 0.0), 
 	m_ref_histogram(m_ref_real_bins, 0.0),
 	m_mov_histogram(m_mov_real_bins + 1/*(1)*/, 0.0),
diff --git a/mia/core/splineparzenmi.hh b/mia/core/splineparzenmi.hh
index f4f3d88..7ca4c24 100644
--- a/mia/core/splineparzenmi.hh
+++ b/mia/core/splineparzenmi.hh
@@ -154,6 +154,9 @@ BOOST_CONCEPT_REQUIRES( ((::boost::ForwardIterator<MovIterator>))
 {
 	std::fill(m_joined_histogram.begin(), m_joined_histogram.end(), 0.0); 
 
+	assert(mov_begin != mov_end); 
+	assert(ref_begin != ref_end); 
+
 	if (m_mov_max < m_mov_min) {
 		// (re)evaluate the ranges 
 		auto mov_range = get_reduced_range(mov_begin, mov_end); 
diff --git a/mia/core/test_attributes.cc b/mia/core/test_attributes.cc
index 50893be..2a4f5bb 100644
--- a/mia/core/test_attributes.cc
+++ b/mia/core/test_attributes.cc
@@ -199,16 +199,16 @@ BOOST_AUTO_TEST_CASE( test_attributes )
 	attr_list["string_attr"] = PAttribute(new CStringAttribute(test_string));
 
 	CIntAttribute *int_attr = dynamic_cast<CIntAttribute*>(attr_list["int_attr"].get());
-	BOOST_CHECK(int_attr);
+	BOOST_REQUIRE(int_attr);
 	BOOST_CHECK(*int_attr == 1);
 
 
 	CFloatAttribute *float_attr = dynamic_cast<CFloatAttribute*>(attr_list["float_attr"].get());
-	BOOST_CHECK(float_attr);
+	BOOST_REQUIRE(float_attr);
 	BOOST_CHECK(*float_attr == 1.0f);
 
 	CStringAttribute *string_attr = dynamic_cast<CStringAttribute*>(attr_list["string_attr"].get());
-	BOOST_CHECK(string_attr);
+	BOOST_REQUIRE(string_attr);
 	string s =  *string_attr;
 	BOOST_CHECK(test_string ==  s);
 
@@ -220,12 +220,12 @@ BOOST_AUTO_TEST_CASE( test_attributes )
 
 	CAttributedData data1(PAttributeMap(new CAttributeMap(attr_list)));
 	int_attr = dynamic_cast<CIntAttribute*>(data1.get_attribute("int_attr").get());
-	BOOST_CHECK(int_attr);
+	BOOST_REQUIRE(int_attr);
 	BOOST_CHECK(*int_attr == 1);
 
 	CAttributedData data2(data1);
 	int_attr = dynamic_cast<CIntAttribute*>(data2.get_attribute("int_attr").get());
-	BOOST_CHECK(int_attr);
+	BOOST_REQUIRE(int_attr);
 	BOOST_CHECK(*int_attr == 1);
 
 	int kk = get_attribute_as<int>(*data2.get_attribute("int_attr"));
@@ -233,11 +233,11 @@ BOOST_AUTO_TEST_CASE( test_attributes )
 
 	data2.set_attribute("int_attr", PAttribute(new CIntAttribute(2)));
 	int_attr = dynamic_cast<CIntAttribute*>(data2.get_attribute("int_attr").get());
-	BOOST_CHECK(int_attr);
+	BOOST_REQUIRE(int_attr);
 	BOOST_CHECK(*int_attr == 2);
 
 	int_attr = dynamic_cast<CIntAttribute*>(data1.get_attribute("int_attr").get());
-	BOOST_CHECK(int_attr);
+	BOOST_REQUIRE(int_attr);
 	BOOST_CHECK(*int_attr == 1);
 
 	CAttributedData data3;
diff --git a/mia/core/test_cmdlineparser.cc b/mia/core/test_cmdlineparser.cc
index 125f8fc..07376ee 100644
--- a/mia/core/test_cmdlineparser.cc
+++ b/mia/core/test_cmdlineparser.cc
@@ -40,7 +40,11 @@ private:
 
 };
 
-const SProgramDescription general_help{
+#define IF_THIS(A)  \
+	{ if (A) cvdebug() << #A << " is true\n"; }
+
+
+const SProgramDescription general_help {
 	{pdi_group, "Test"}, 
 	{pdi_short, "program tests"}, 
 	{pdi_description, "This program tests the command line parser."}, 
@@ -229,8 +233,8 @@ BOOST_FIXTURE_TEST_CASE( test_dict_option, CmdlineParserFixture )
 	options.push_back("-dtwo");
 	BOOST_CHECK_EQUAL(olist.parse(options.size(), &options[0]), CCmdOptionList::hr_no); 
 
-	BOOST_CHECK( olist.get_remaining().size() == 0);
-	BOOST_CHECK(value == te_two);
+	BOOST_CHECK_EQUAL( olist.get_remaining().size(), 0);
+	BOOST_CHECK_EQUAL( value, te_two);
 }
 
 BOOST_FIXTURE_TEST_CASE( test_flagstring_option, CmdlineParserFixture )
@@ -256,7 +260,7 @@ BOOST_FIXTURE_TEST_CASE( test_flagstring_option, CmdlineParserFixture )
 	options.push_back("ot");
 	BOOST_CHECK_EQUAL(olist.parse(options.size(), &options[0]), CCmdOptionList::hr_no); 
 
-	BOOST_CHECK( olist.get_remaining().size() == 0);
+	BOOST_CHECK_EQUAL( olist.get_remaining().size(), 0);
 	BOOST_CHECK(value == te_two || te_one);
 }
 
@@ -335,7 +339,7 @@ BOOST_FIXTURE_TEST_CASE( test_parser_errors1, CmdlineParserFixture )
 	CCmdOptionList olist(general_help);
 	olist.add(make_opt(bool_value, "bool", 'H', "a bool option"));
 
-	BOOST_CHECK_THROW((olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
+	BOOST_CHECK_THROW(IF_THIS(olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
 }
 
 BOOST_FIXTURE_TEST_CASE( test_missing_argument_short, CmdlineParserFixture )
@@ -346,7 +350,7 @@ BOOST_FIXTURE_TEST_CASE( test_missing_argument_short, CmdlineParserFixture )
 	CCmdOptionList olist(general_help);
 	olist.add(make_opt(test, "lala", 'i', "a string option"));
 	
-	BOOST_CHECK_THROW( (olist.parse(options.size(), &options[0])== CCmdOptionList::hr_no), invalid_argument); 
+	BOOST_CHECK_THROW( IF_THIS(olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
 }
 
 BOOST_FIXTURE_TEST_CASE( test_missing_string_argument_long, CmdlineParserFixture )
@@ -357,7 +361,7 @@ BOOST_FIXTURE_TEST_CASE( test_missing_string_argument_long, CmdlineParserFixture
 	CCmdOptionList olist(general_help);
 	olist.add(make_opt(test, "lala", 'i', "a string option"));
 	
-	BOOST_CHECK_THROW( (olist.parse(options.size(), &options[0])== CCmdOptionList::hr_no), invalid_argument); 
+	BOOST_CHECK_THROW( IF_THIS(olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
 }
 
 
@@ -371,7 +375,7 @@ BOOST_FIXTURE_TEST_CASE( test_parser_errors2, CmdlineParserFixture )
 	CCmdOptionList olist(general_help);
 	olist.add(make_opt(bool_value, "bool", 'H', "a bool option"));
 
-	BOOST_CHECK_THROW((olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
+	BOOST_CHECK_THROW(IF_THIS(olist.parse(options.size(), &options[0]) == CCmdOptionList::hr_no), invalid_argument); 
 }
 
 const SProgramDescription general_help_test = {
@@ -462,9 +466,10 @@ BOOST_FIXTURE_TEST_CASE( test_parser_help_output, CmdlineParserFixture )
 	BOOST_CHECK_EQUAL(output.str(), test); 
 
 	if (output.str() != test) {
-		auto io = output.str().begin(); 
+		const auto ostr = output.str(); 
+		auto io = ostr.begin(); 
 		auto it = test.begin(); 
-		while (io != output.str().end() && it != test.end()) {
+		while (io != ostr.end() && it != test.end()) {
 			if (*io == *it) 
 				cerr << *io; 
 			else {
diff --git a/mia/core/test_filter.cc b/mia/core/test_filter.cc
index 6bca416..e5bf7df 100644
--- a/mia/core/test_filter.cc
+++ b/mia/core/test_filter.cc
@@ -50,7 +50,8 @@ private:
 
 template <class T>
 struct TestPixelType : public TestPixelTypeBase {
-	TestPixelType():TestPixelTypeBase((EPixelType)pixel_type<T>::value)
+	TestPixelType():TestPixelTypeBase((EPixelType)pixel_type<T>::value), 
+			value(T())
 	{
 	}
 
diff --git a/mia/core/test_histogram.cc b/mia/core/test_histogram.cc
index f083b12..e1e2e2a 100644
--- a/mia/core/test_histogram.cc
+++ b/mia/core/test_histogram.cc
@@ -36,6 +36,17 @@ using namespace boost::unit_test;
 namespace bfs=::boost::filesystem;
 
 
+BOOST_AUTO_TEST_CASE( test_empty_histogram)
+{
+	THistogram<CUBHistogramFeeder> h(CUBHistogramFeeder(0,0,0));
+
+	BOOST_CHECK_EQUAL(h.average(), 0); 
+	BOOST_CHECK_EQUAL(h.deviation(), 0); 
+	BOOST_CHECK_EQUAL(h.median(), 0);
+	BOOST_CHECK_EQUAL(h.MAD(), 0);
+	
+}
+
 BOOST_AUTO_TEST_CASE( test_histogram)
 {
 	unsigned char init_data[10] = { 1, 2, 3, 4, 5, 5, 5, 5, 4, 3 };
diff --git a/mia/core/test_iohandler.cc b/mia/core/test_iohandler.cc
index 30b9167..f2744e2 100644
--- a/mia/core/test_iohandler.cc
+++ b/mia/core/test_iohandler.cc
@@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_CASE(  test_preferred_suffix, DummyPluginFixture )
 	BOOST_CHECK_EQUAL(handler.get_preferred_suffix("datapool"), "@");
 	BOOST_CHECK_EQUAL(handler.get_preferred_suffix("la"), "hey");
 
-	BOOST_CHECK_THROW(handler.get_preferred_suffix("nonsense"), invalid_argument);
+	BOOST_CHECK_THROW(handler.get_preferred_suffix("nonsense"), runtime_error);
 }
 
 BOOST_FIXTURE_TEST_CASE(  test_datapool_io, DummyPluginFixture )
diff --git a/mia/core/test_shape.cc b/mia/core/test_shape.cc
index ac304bf..8adb6ee 100644
--- a/mia/core/test_shape.cc
+++ b/mia/core/test_shape.cc
@@ -26,6 +26,9 @@
 template <typename T> 
 struct pass_type {
 	typedef T value_type; 
+
+	pass_type(): x(T()){}; 
+	pass_type(T _x): x(_x){}; 
 	T x; 
 }; 
 
diff --git a/mia/core/test_streamredir.cc b/mia/core/test_streamredir.cc
index 62eaa36..70e8601 100644
--- a/mia/core/test_streamredir.cc
+++ b/mia/core/test_streamredir.cc
@@ -62,16 +62,14 @@ BOOST_AUTO_TEST_CASE( test_streamredir )
 {
 	ostringstream test;
 
-	Cstreamredir *s = new Cstreamredir(test);
-	ostream test_output(s);
+	Cstreamredir s(test);
+	ostream test_output(&s);
 
 	test_output << "test\n";
 	cvdebug() << "test string >>" << test.str() << "<<\n";
 
 	streambuf *os = test_output.rdbuf(0);
-	BOOST_CHECK_EQUAL((void*)os, (void *)s);
-	delete os;
-
+	BOOST_CHECK_EQUAL((void*)os, (void *)&s);
 
 	BOOST_CHECK(test.str() == "test");
 }
@@ -80,13 +78,10 @@ BOOST_AUTO_TEST_CASE( test_streamredir_overflow )
 {
 	ostringstream test;
 
-	Cstreamredir *s = new Cstreamredir(test);
-	ostream test_output(s);
+	Cstreamredir s(test);
+	ostream test_output(&s);
 
 	for (size_t i = 0; i < 2000; ++i) {
 		test_output << i;
 	}
-
-	streambuf *os = test_output.rdbuf(0);
-	delete os;
 }
diff --git a/mia/core/threadedmsg.cc b/mia/core/threadedmsg.cc
index 678af07..eb5deca 100644
--- a/mia/core/threadedmsg.cc
+++ b/mia/core/threadedmsg.cc
@@ -104,7 +104,9 @@ std::streamsize thread_streamredir::xsputn( const char * s, std::streamsize n )
 void thread_streamredir::send_to_master()
 {
 	CScopedLock lock(m_master_lock); 
-	*m_master << "[thread " << setw(3) << setfill('0') << m_id << "]:" << m_buffer.str() << "\n"; 
+	char oldfill = m_master->fill(); 
+	*m_master << "[thread " << setw(3) << setfill('0') << m_id << setfill(oldfill) << "]:" 
+		  << m_buffer.str() << "\n"; 
 	m_buffer.str(""); 
 	m_buffer.clear(); 
 }
diff --git a/mia/core/threadedmsg.hh b/mia/core/threadedmsg.hh
index c7ef296..51772c6 100644
--- a/mia/core/threadedmsg.hh
+++ b/mia/core/threadedmsg.hh
@@ -68,7 +68,6 @@ private:
 	static void do_set_master_stream(std::ostream& master); 
 	
 	
-
 	std::ostream& m_old; 
 
 }; 
diff --git a/mia/core/waveletslopeclassifier.cc b/mia/core/waveletslopeclassifier.cc
index ab15c1a..5139b56 100644
--- a/mia/core/waveletslopeclassifier.cc
+++ b/mia/core/waveletslopeclassifier.cc
@@ -155,6 +155,7 @@ CWaveletSlopeClassifierImpl::CWaveletSlopeClassifierImpl():
 	Baseline_idx(-1), 
 	free_breathing(false), 
 	max_movment_energy(0.0), 
+	n_movement_components(0), 
 	result(CWaveletSlopeClassifier::wsc_fail)
 {
 }
@@ -169,6 +170,7 @@ CWaveletSlopeClassifierImpl::CWaveletSlopeClassifierImpl(const CWaveletSlopeClas
 	Baseline_idx(-1), 
 	free_breathing(false), 
 	max_movment_energy(0.0), 
+	n_movement_components(0), 
 	result(CWaveletSlopeClassifier::wsc_fail)
 {
 	vector<PSlopeStatistics> vstats; 
diff --git a/mia/internal/autotest.hh b/mia/internal/autotest.hh
index 45f7dd7..d65977c 100644
--- a/mia/internal/autotest.hh
+++ b/mia/internal/autotest.hh
@@ -37,8 +37,8 @@
 #include <boost/test/floating_point_comparison.hpp>
 
 #include <miaconfig.h>
-#include <mia/core/msgstream.hh>
 #include <mia/core/cmdlineparser.hh>
+#include <mia/internal/main.hh>
 
 const mia::SProgramDescription description = {
 	{mia::pdi_group, "Test"}, 
@@ -50,7 +50,7 @@ const mia::SProgramDescription description = {
 
 
 int BOOST_TEST_CALL_DECL
-main( int argc, char* argv[] )
+do_main( int argc, char* argv[] )
 {
 	// set the plug-in path for tests 
 	setenv("MIA_PLUGIN_TESTPATH", MIA_BUILD_ROOT "/plugintest/" PLUGIN_INSTALL_PATH ,1);
@@ -64,4 +64,6 @@ main( int argc, char* argv[] )
 	return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
 }
 
+MIA_MAIN(do_main); 
+
 #endif 
diff --git a/mia/internal/main.hh b/mia/internal/main.hh
index e78e009..e15a4da 100644
--- a/mia/internal/main.hh
+++ b/mia/internal/main.hh
@@ -24,31 +24,31 @@
 #include <mia/core/msgstream.hh>
 
 
-#define MIA_MAIN(callback) \
-	int main( int argc, char *argv[] ) \
-	{					 \
-	        try {				 \
-		      auto verb = getenv("MIA_INITIAL_VERBOSITY");      \
+#define MIA_MAIN(callback)						\
+	int main( int argc, char *argv[] )				\
+	{								\
+	        try {							\
+			auto verb = getenv("MIA_INITIAL_VERBOSITY");	\
 		      if (verb) {                                       \
-                            auto level = g_verbose_dict.get_value(verb);\
-			    vstream::instance().set_verbosity(level);   \
+			      auto level = mia::g_verbose_dict.get_value(verb); \
+			      mia::vstream::instance().set_verbosity(level); \
                       }                                                 \
-  	              return callback(argc, argv);                       \
+  	              return callback(argc, argv);			\
 	        }                                                       \
 		catch (const std::runtime_error &e){			\
-			 std::cerr << argv[0] << " runtime error: " << e.what() << endl; \
- 	        }                                                                    \
- 	        catch (const std::invalid_argument &e){                              \
-		        std::cerr << argv[0] << " invalid argument: " << e.what() << endl;\
-	        }                                                                    \
- 	        catch (const std::logic_error &e){                                   \
-		        std::cerr << argv[0] << " logic error: " << e.what() << endl;\
-	        }                                                                    \
-	        catch (const std::exception& e){			             \
-		        std::cerr << argv[0] << " error: " << e.what() << endl;      \
-	        }                                                                    \
-	        catch (...){                                                         \
-		       std::cerr << argv[0] << " unknown exception" << endl;         \
-	}                                                                            \
-	return EXIT_FAILURE;                                                         \
-}
+			std::cerr << argv[0] << " runtime error: " << e.what() << std::endl; \
+ 	        }							\
+ 	        catch (const std::invalid_argument &e){			\
+		        std::cerr << argv[0] << " invalid argument: " << e.what() << std::endl;	\
+	        }							\
+ 	        catch (const std::logic_error &e){			\
+		        std::cerr << argv[0] << " logic error: " << e.what() << std::endl; \
+	        }							\
+	        catch (const std::exception& e){			\
+		        std::cerr << argv[0] << " error: " << e.what() << std::endl; \
+	        }							\
+	        catch (...){						\
+			std::cerr << argv[0] << " unknown exception" << std::endl; \
+		}							\
+		return EXIT_FAILURE;					\
+	}
diff --git a/mia/internal/plugintester.hh b/mia/internal/plugintester.hh
index b2f0f64..1cb17ed 100644
--- a/mia/internal/plugintester.hh
+++ b/mia/internal/plugintester.hh
@@ -35,8 +35,8 @@
 
 #include <miaconfig.h>
 #include <mia/core/factory.hh>
-#include <mia/core/msgstream.hh>
 #include <mia/core/cmdlineparser.hh>
+#include <mia/internal/main.hh>
 
 NS_MIA_BEGIN 
 
@@ -64,7 +64,7 @@ const mia::SProgramDescription description = {
 };
 
 int BOOST_TEST_CALL_DECL
-main( int argc, char* argv[] )
+do_main( int argc, char* argv[] )
 {
 	setenv("MIA_PLUGIN_TESTPATH", MIA_BUILD_ROOT "/plugintest/" PLUGIN_INSTALL_PATH,1);
 #ifdef WIN32
@@ -76,3 +76,5 @@ main( int argc, char* argv[] )
 	mia::cvdebug() << "Initialize test ...\n"; 
 	return ::boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
 }
+
+MIA_MAIN(do_main); 
diff --git a/mia/template/mi.hh b/mia/template/mi.hh
index 87b0249..fbc2637 100644
--- a/mia/template/mi.hh
+++ b/mia/template/mi.hh
@@ -100,7 +100,6 @@ struct FEvalForce: public mia::TFilter<float> {
 	}
 private: 
 	Force& m_force; 
-	float m_scale; 
 	mia::CSplineParzenMI& m_parzen_mi;
 }; 
 		
diff --git a/mia/template/ssd.hh b/mia/template/ssd.hh
index 6f38564..c8a1cde 100644
--- a/mia/template/ssd.hh
+++ b/mia/template/ssd.hh
@@ -118,7 +118,6 @@ struct FEvalForce: public mia::TFilter<float> {
 	}
 private: 
 	Force& m_force; 
-	float m_scale; 
 	bool m_normalize; 
 }; 
 		
diff --git a/src/2davgmasked.cc b/src/2davgmasked.cc
index b3dac1c..65ea59e 100644
--- a/src/2davgmasked.cc
+++ b/src/2davgmasked.cc
@@ -126,8 +126,13 @@ int do_main( int argc, char *argv[] )
 	if (!mask_image_list.get() || mask_image_list->empty())
 		throw invalid_argument("no mask found");
 
-	const C2DUBImage *mask = dynamic_cast<const C2DUBImage *>( mask_image_list->begin()->get() );
+	const C2DImage *mask_image = mask_image_list->begin()->get(); 
+	const C2DUBImage *mask = dynamic_cast<const C2DUBImage *>( mask_image );
 
+	if (!mask) 
+		throw create_exception<invalid_argument>("Mask image must be an image with pixel type byte, but pixel type '", 
+						      CPixelTypeDict.get_name(mask_image->get_pixel_type()), 
+						      "' was provided."); 
 	C2DStat stat(*mask);
 
 	for (size_t i = start_filenum; i < end_filenum; ++i) {
diff --git a/src/2deval-transformquantity.cc b/src/2deval-transformquantity.cc
index 69fec39..76d8dfc 100644
--- a/src/2deval-transformquantity.cc
+++ b/src/2deval-transformquantity.cc
@@ -48,10 +48,10 @@ using namespace mia;
 const SProgramDescription g_description = {
 	{pdi_group,"Tools for the Analysis of 2D image series"},
 	{pdi_short, "Evaluate derivative of a transformation"}, 
-	{pdi_description,"Get derivative a transformation obtained by by using image registration for "
+	{pdi_description,"Get derivative a transformation obtained by using image registration for "
 	 "any given positions in 2D. "
 	 "The position data is given in CSV format:\n"
-	 "   id;time;x;y;z;reserved\n"
+	 "   id;time;x;y;reserved\n"
 	 "The output data will be stored in a binary file with an ascii header describing the data. "
 	 "An example header is given below:\n\n"
 	 "MIA\n" 
@@ -63,11 +63,11 @@ const SProgramDescription g_description = {
 	 "  interpretation=strain #interpretation of elements (strain|derivative)\n"
 	 "  style=sparse   #storage style (sparse|grid) \n"
 	 "  repn=float32   #representation of values \n"
-	 "  size=1000 1000 200 #grid size of the transformation\n"
+	 "  size=1000 1000 #grid size of the transformation\n"
 	 "  endian=low     #endianess of binary data (low|big) \n" 
 	 "}\n\n"
 	 
-	 "This example header has to be interpreted like follows: three-dimensional data, each entry consists of 13 values "
+	 "This example header has to be interpreted like follows: two-dimensional data, each entry consists of 7 values "
 	 "the values etry consists of a 2D vector, a scalar, and a 2x2 matrix (saved in row-major format)."
 	 "The data records represent strain tensors, and only a sparse set of points is given. "
 	 "The values are given as single floating point (32 bit). "
@@ -254,7 +254,7 @@ int do_main( int argc, char *argv[] )
 		transform(trackpoints.begin(), trackpoints.end(), back_inserter(tensorfield), translater); 
 		
 		element_size = sizeof(SSparseStracPoint)/sizeof(float); 
-		components.assign("vector3,scalar,matrix3x3"); 
+		components.assign("vector2,scalar,matrix2x2"); 
 		style.assign("sparse"); 
 
 		unsigned int nelements = static_cast<unsigned int>(tensorfield.size()); 
diff --git a/src/2dimagefilterstack.cc b/src/2dimagefilterstack.cc
index 24d6c8c..bb316b2 100644
--- a/src/2dimagefilterstack.cc
+++ b/src/2dimagefilterstack.cc
@@ -60,7 +60,6 @@ int do_main( int argc, char *argv[] )
 	string in_filename;
 	string out_filename;
 	string out_type;
-	bool help_plugins = false;
 
 	size_t startid = 0; 
 	size_t endid = numeric_limits<int>::max(); 
@@ -97,11 +96,6 @@ int do_main( int argc, char *argv[] )
 	cvdebug() << "IO supported types: " << imageio.get_plugin_names() << "\n";
 	cvdebug() << "supported filters: " << filter_plugins.get_plugin_names() << "\n";
 
-	if (help_plugins) {
-		filter_plugins.print_help(cout);
-		return EXIT_SUCCESS;
-	}
-
 	if ( filter_chain.empty() )
 		cvwarn() << "no filters given, just copy\n";
 
diff --git a/src/2dmultiimageto3d.cc b/src/2dmultiimageto3d.cc
new file mode 100644
index 0000000..3bc979f
--- /dev/null
+++ b/src/2dmultiimageto3d.cc
@@ -0,0 +1,81 @@
+/* -*- mia-c++  -*-
+ *
+ * This file is part of MIA - a toolbox for medical image analysis 
+ * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
+ *
+ * MIA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIA; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <iostream>
+#include <string>
+#include <stdexcept>
+#include <sstream>
+
+#include <mia/core.hh>
+#include <mia/2d/imageio.hh>
+#include <mia/3d/imageio.hh>
+#include <mia/3d/imagecollect.hh>
+
+
+using namespace std;
+NS_MIA_USE;
+
+
+const SProgramDescription g_description = {
+        {pdi_group, "Image conversion"}, 
+	{pdi_short, "Convert a 2D multi-record image to a 3D image."}, 
+	{pdi_description, "This program is used to convert a 2D multi-image file to a 3D image."}, 
+	{pdi_example_descr, "Convert an series of images stored in a 2D image container multiimage2d.v to a 3D image image3d.v."}, 
+	{pdi_example_code, "-i multiimage2d.v -o image3d.v"}
+}; 
+
+int do_main( int argc, char *argv[])
+{
+
+	string in_filename;
+	string out_filename;
+
+	const auto& imageio2d = C2DImageIOPluginHandler::instance();
+	const auto& imageio3d = C3DImageIOPluginHandler::instance();
+
+	CCmdOptionList options(g_description);
+	options.add(make_opt( in_filename, "in-file", 'i',
+				    "input images", CCmdOption::required, &imageio2d));
+	options.add(make_opt( out_filename, "out-file", 'o',
+				    "output image", CCmdOption::required, &imageio3d));
+
+	if (options.parse(argc, argv) != CCmdOptionList::hr_no)
+		return EXIT_SUCCESS; 
+
+
+	// read image
+	C2DImageIOPluginHandler::Instance::PData  in_image_list = imageio2d.load(in_filename);
+	if (!in_image_list)
+		throw create_exception<invalid_argument>("No images found in '", in_filename, "'");
+
+	C3DImageCollector ic(in_image_list->size());
+
+	for_each(in_image_list->begin(), in_image_list->end(), 
+		 [&ic](P2DImage image){ ic.add(*image);}); 
+	
+	if (!save_image(out_filename, ic.get_result())) 
+		throw create_exception<runtime_error>("Unable to write image to '", out_filename, "'");
+	
+	return EXIT_SUCCESS;
+}
+
+
+#include <mia/internal/main.hh>
+MIA_MAIN(do_main)
diff --git a/src/2dmyocard-segment.cc b/src/2dmyocard-segment.cc
index b09bc39..55121db 100644
--- a/src/2dmyocard-segment.cc
+++ b/src/2dmyocard-segment.cc
@@ -488,7 +488,7 @@ int do_main( int argc, char *argv[] )
 	if (rv_idx < 0) 
 		throw runtime_error("RV could not be identified"); 
 
-	if (rv_idx < 0) 
+	if (lv_idx < 0) 
 		throw runtime_error("LV could not be identified"); 
 
 	if (perf_idx < 0) 
diff --git a/src/2dmyoica-nonrigid2.cc b/src/2dmyoica-nonrigid2.cc
index d3b4519..e5c637f 100644
--- a/src/2dmyoica-nonrigid2.cc
+++ b/src/2dmyoica-nonrigid2.cc
@@ -283,7 +283,7 @@ int do_main( int argc, char *argv[] )
 	bool do_continue=true; 
 	bool lastpass = false; 
 
-	while (do_continue){
+	while (do_continue || lastpass){
 		++current_pass; 
 		cvmsg() << "Registration pass " << current_pass << "\n"; 
 		transformations = 
@@ -310,7 +310,9 @@ int do_main( int argc, char *argv[] )
 		references_float = ica2.get_references(); 
 		transform(references_float.begin(), references_float.end(), 
 			  references.begin(), FWrapStaticDataInSharedPointer<C2DImage>()); 
-		do_continue =  (!pass || current_pass < pass) && ica2.has_movement(); 
+
+		const bool can_one_more_pass = !pass || current_pass < pass; 
+		do_continue = can_one_more_pass && ica2.has_movement(); 
 		if (!do_continue && !save_crop_feature.empty()) {
 			stringstream cfile; 
 			cfile << save_crop_feature << "-final.txt"; 
@@ -321,7 +323,7 @@ int do_main( int argc, char *argv[] )
 		}
 		
 		// run one more pass if the limit is not reached and no movement identified
-		lastpass = (!do_continue && (!pass || current_pass < pass)); 
+		lastpass = (!do_continue && can_one_more_pass); 
 
 	}
 
diff --git a/src/2dmyoperiodic-nonrigid.cc b/src/2dmyoperiodic-nonrigid.cc
index 0c16983..17c5757 100644
--- a/src/2dmyoperiodic-nonrigid.cc
+++ b/src/2dmyoperiodic-nonrigid.cc
@@ -255,22 +255,23 @@ void C2DMyocardPeriodicRegistration::run_final_pass(C2DImageSeries& images,
 
 		if (i == *low_index)
 			continue; 
-		
-		if (i == *high_index) {
-			++low_index; 
-			++high_index; 
-			if (high_index != subset.end())
-				continue;
-		}
 
 		// the last images may be registered using SSD without interpolating references 
 		P2DImage ref; 
 		if (high_index != subset.end()) {
 
+			if (i == *high_index) {
+				++low_index; 
+				++high_index; 
+				continue;
+			}
+				
 			float w = float(*high_index - i)/(*high_index - *low_index);  
 			FAddWeighted lerp(w);
 			
-			cvmsg() << "create " << i << " from [" << *low_index << ", " << *high_index << "] w = "<< w <<"\n"; 
+			cvmsg() << "create " << i << " from [" << *low_index << ", " 
+				<< *high_index << "] w = "<< w <<"\n"; 
+			
 			ref = mia::filter(lerp, *images[*high_index], *images[*low_index]); 
 			if (m_params.save_ref) {
 				stringstream refname; 
diff --git a/src/2dsegment-ahmed.cc b/src/2dsegment-ahmed.cc
index 7d8f18d..6fb5dfe 100644
--- a/src/2dsegment-ahmed.cc
+++ b/src/2dsegment-ahmed.cc
@@ -97,7 +97,9 @@ CSegment2d::CSegment2d(bool bg_correct, int ncc,
 	_M_nClasses(ncc), 
 	_M_bg_correct(bg_correct), 
 	_M_class_centers(icc),
-	_M_k(k)
+	_M_k(k), 
+	_M_minh(0), 
+	_M_maxh(0)
 {
 }	
 
diff --git a/src/2dseriescorr.cc b/src/2dseriescorr.cc
index f21e97c..d1370b9 100644
--- a/src/2dseriescorr.cc
+++ b/src/2dseriescorr.cc
@@ -162,6 +162,8 @@ FCorrelationAccumulator::FCorrelationAccumulator(const C2DBounds & _size):
 	sxy_vertical(_size),
 	sx(_size),
 	size(_size),
+	corr_hor(nullptr), 
+	corr_ver(nullptr), 
 	len(0)
 {
 }
diff --git a/src/2dtransformation-to-strain.cc b/src/2dtransformation-to-strain.cc
index 2d70bad..cf86da9 100644
--- a/src/2dtransformation-to-strain.cc
+++ b/src/2dtransformation-to-strain.cc
@@ -67,7 +67,7 @@ int do_main(int argc, char **argv)
 	auto o = tensorfield.begin(); 
 
 	for (unsigned int y = 0; y < size.y; ++y) 
-		for (unsigned int x = 0; x < size.x; ++x, o += 9) {
+		for (unsigned int x = 0; x < size.x; ++x, o += 4) {
 			auto d = transformation->derivative_at(x,y); 
 			auto m = d * d.transposed() - C2DFMatrix::_1;
 			
diff --git a/src/3dprealign-nonrigid.cc b/src/3dprealign-nonrigid.cc
index e74a80c..c565bac 100644
--- a/src/3dprealign-nonrigid.cc
+++ b/src/3dprealign-nonrigid.cc
@@ -49,13 +49,14 @@ const SProgramDescription g_description = {
 	{pdi_description, "This program runs the non-rigid registration of an image series "
 	 "by first registering an already aligned subset of the images to one reference, "
 	 "and then by registering the remaining images by using synthetic references. "
-	 "The is a 3D version of G. Wollny, M-J Ledesma-Cabryo, P.Kellman, and A.Santos, \"Exploiting "
-	 "Quasiperiodicity in Motion Correction of Free-Breathing,\" "
+	 "The is a 3D version of G. Wollny, M-J Ledesma-Cabryo, P.Kellman, and A.Santos, "
+	 "\"Exploiting Quasiperiodicity in Motion Correction of Free-Breathing,\" "
 	 "IEEE Transactions on Medical Imaging, 29(8), 2010."}, 
-	{pdi_example_descr, "Register the image series given by images imageXXXX.v by optimizing a spline based "
-	 "transformation with a coefficient rate of 16 pixel ,skipping two images at the "
-	 "beginning and using normalized gradient fields as initial cost measure "
-	 "and SSD as final measure. Penalize the transformation by using divcurl with aweight of 2.0. "
+	{pdi_example_descr, "Register the image series given by images imageXXXX.v by "
+	 "optimizing a spline based transformation with a coefficient rate of 16 pixel, "
+	 "skipping two ""images at the beginning and using normalized gradient fields "
+	 "as initial cost measure and SSD as final measure. Penalize the transformation "
+	 "by using divcurl with aweight of 2.0. "
 	 "As optimizer an nlopt based newton method is used."}, 
 	{pdi_example_code, "mia-3dprealign-nonrigid  -i imageXXXX.v -o registered -t vista -k 2"
 	 "-F spline:rate=16,penalty=[divcurl:weight=2] -1 image:cost=[ngf:eval=ds] -2 image:cost=ssd "
@@ -80,7 +81,8 @@ struct FAddWeighted: public TFilter<P3DImage> {
 	P3DImage operator() (const T3DImage<T>& a, const T3DImage<S>& b) const
 	{
 		if (a.get_size() != b.get_size()) {
-			throw invalid_argument("input images cann not be combined because they differ in size");
+			throw invalid_argument("input images cann not be "
+					       "combined because they differ in size");
 		}
 		T3DImage<T> *result = new T3DImage<T>(a.get_size(), a);
 		auto r = result->begin();
@@ -124,13 +126,14 @@ public:
 	};
 
 	C3DMyocardPeriodicRegistration(const RegistrationParams& params); 
-	vector<P3DTransformation> run(C3DImageSeries& images); 
+	vector<P3DTransformation> run(C3DImageSeries& images, size_t preskip, size_t postskip); 
 	size_t get_ref_idx()const; 
 
 private: 
 	vector<size_t>  get_high_contrast_candidates(const C3DImageSeries& images, 
 						     size_t startidx, size_t endidx); 
-	vector<size_t> get_prealigned_subset(const C3DImageSeries& images);  
+	vector<size_t> get_prealigned_subset(const C3DImageSeries& images, 
+					     size_t preskip, size_t postskip);  
 	void run_initial_pass(C3DImageSeries& images, 
 			      vector<P3DTransformation>& transforms, 
 			      const vector<size_t>& subset); 
@@ -160,8 +163,9 @@ public:
 	}
 };
 
-vector<size_t>  C3DMyocardPeriodicRegistration::get_high_contrast_candidates(const C3DImageSeries& images, 
-									     size_t startidx, size_t endidx)
+vector<size_t>  
+C3DMyocardPeriodicRegistration::get_high_contrast_candidates(const C3DImageSeries& images, 
+							     size_t startidx, size_t endidx)
 {
 	CStatsEvaluator sev; 
 	priority_queue<IdxVariation> q; 
@@ -182,11 +186,14 @@ vector<size_t>  C3DMyocardPeriodicRegistration::get_high_contrast_candidates(con
 	return result; 
 }
 
-vector<size_t> C3DMyocardPeriodicRegistration::get_prealigned_subset(const C3DImageSeries& images) 
+vector<size_t> C3DMyocardPeriodicRegistration::get_prealigned_subset(const C3DImageSeries& images, 
+								     size_t preskip, size_t postskip) 
 {
+	assert(postskip < images.size()); 
+	assert(preskip < images.size() - postskip); 
+	
 	cvmsg() << "estimate prealigned subset ...\n"; 
-	vector<size_t> candidates = get_high_contrast_candidates(images, 20, images.size()-2); 
-	assert(!candidates.empty()); 
+	vector<size_t> candidates = get_high_contrast_candidates(images, preskip, images.size()-2); 
 
 	C3DSimilarityProfile best_series(m_params.series_select_cost, images, candidates[0]); 
 	m_ref = candidates[0]; 
@@ -232,9 +239,11 @@ void C3DMyocardPeriodicRegistration::run_final_pass(C3DImageSeries& images,
 						    vector<P3DTransformation>& transforms, 
 						    const vector<size_t>& subset)
 {
+	assert(!subset.empty()); 
+	
 	cvmsg() << "run final registration pass ...\n"; 
 	C3DFullCostList costs; 
-	// create costs
+
 	costs.push(m_params.pass2_cost); 
 	
 	C3DNonrigidRegister nr(costs, 
@@ -250,16 +259,17 @@ void C3DMyocardPeriodicRegistration::run_final_pass(C3DImageSeries& images,
 		if (i == *low_index)
 			continue; 
 		
-		if (i == *high_index) {
-			++low_index; 
-			++high_index; 
-			if (high_index != subset.end())
-				continue;
-		}
-
+		
 		// the last images may be registered using SSD without interpolating references 
 		P3DImage ref; 
 		if (high_index != subset.end()) {
+
+			if (i == *high_index) {
+				++low_index; 
+				++high_index; 
+				continue;
+			}
+
 			float w = float(*high_index - i)/(*high_index - *low_index);  
 			FAddWeighted lerp(w);
 			
@@ -271,7 +281,7 @@ void C3DMyocardPeriodicRegistration::run_final_pass(C3DImageSeries& images,
 				cvmsg() << "Save reference to " << refname.str() << "\n"; 
 			}
 		}else
-			ref = images[*low_index]; 
+			ref = images[*low_index];	
 
 		cvmsg() << "Register image " << i << "\n"; 		
 		P3DTransformation transform = nr.run(images[i], ref);
@@ -286,10 +296,10 @@ C3DMyocardPeriodicRegistration::C3DMyocardPeriodicRegistration(const Registratio
 {
 }
 
-vector<P3DTransformation> C3DMyocardPeriodicRegistration::run(C3DImageSeries& images)
+vector<P3DTransformation> C3DMyocardPeriodicRegistration::run(C3DImageSeries& images, size_t preskip, size_t postskip)
 {
 	vector<P3DTransformation> transforms(images.size()); 
-	vector<size_t> subset = get_prealigned_subset(images); 
+	vector<size_t> subset = get_prealigned_subset(images, preskip, postskip); 
 	run_initial_pass(images, transforms, subset); 
 	run_final_pass(images, transforms, subset); 
 	return transforms; 
@@ -321,13 +331,16 @@ int do_main( int argc, char *argv[] )
 	string reference_index_file; 
 
 	size_t skip = 0; 
-	
+	size_t preskip = 20; 
+	size_t postskip	= 2; 
+
 	C3DMyocardPeriodicRegistration::RegistrationParams params;
 
 	CCmdOptionList options(g_description);
 	
 	options.set_group("\nFile-IO");
-	options.add(make_opt( in_filename, "in-file", 'i', "input images following the naming pattern nameXXXX.ext", 
+	options.add(make_opt( in_filename, "in-file", 'i', 
+			      "input images following the naming pattern nameXXXX.ext", 
 			      CCmdOption::required, &C3DImageIOPluginHandler::instance()));
 	options.add(make_opt( registered_filebase, "out-file", 'o', 
 			      "file name base for registered files given as C-format string", 
@@ -339,28 +352,36 @@ int do_main( int argc, char *argv[] )
 	options.set_group("\nPreconditions & Preprocessing"); 
 	options.add(make_opt(skip, "skip", 'k', 
 				   "Skip images at the begin of the series")); 
+
+	options.add(make_opt(preskip, "preskip", 0, 
+			     "Skip images at the beginning+skip of the series when searching for high contrats image"));
+	options.add(make_opt(postskip, "postskip", 0, 
+			     "Skip images at the end of the series when searching for high contrats image"));
+
 	options.add(make_opt(params.max_candidates, "max-candidates", 0, 
 				   "maximum number of candidates for global reference image")); 
-	options.add(make_opt(params.series_select_cost, "image:cost=[ngf:eval=ds]", "cost-series", 'S',
-				   "Const function to use for the analysis of the series")); 
+	options.add(make_opt(params.series_select_cost, "image:cost=[ngf:eval=ds]", 
+			     "cost-series", 'S',
+			     "Const function to use for the analysis of the series")); 
 	options.add(make_opt(reference_index_file, "ref-idx", 0, 
-				   "save reference index number to this file"));  
+			     "save reference index number to this file"));  
 
 
 	options.set_group("\nRegistration"); 
 
 
-	options.add(make_opt( params.minimizer, "gsl:opt=gd,step=0.01", "optimizer", 'O', "Optimizer used for minimization"));
+	options.add(make_opt( params.minimizer, "gsl:opt=gd,step=0.01", "optimizer", 'O', 
+			      "Optimizer used for minimization"));
 	options.add(make_opt( params.mg_levels, "mr-levels", 'l', "multi-resolution levels"));
-
+	
 	options.add(make_opt( params.transform_creator, "spline", "transForm", 'f', 
 				    "transformation type"));
 
 	options.add(make_opt(params.pass1_cost, "image:cost=[ngf:eval=ds]", "cost-subset", '1', 
-				   "Cost function for registration during the subset registration")); 
+			     "Cost function for registration during the subset registration")); 
 
 	options.add(make_opt(params.pass2_cost, "image:cost=ssd", "cost-final", '2', 
-				   "Cost function for registration during the final registration")); 
+			     "Cost function for registration during the final registration")); 
 	
 
 	if (options.parse(argc, argv) != CCmdOptionList::hr_no) 
@@ -370,7 +391,9 @@ int do_main( int argc, char *argv[] )
 	size_t end_filenum  = 0;
 	size_t format_width = 0;
 
-	string src_basename = get_filename_pattern_and_range(in_filename, start_filenum, end_filenum, format_width);
+	string src_basename = 
+		get_filename_pattern_and_range(in_filename, start_filenum, 
+					       end_filenum, format_width);
 
 	C3DImageSeries in_images; 
 	for (size_t i = start_filenum; i < end_filenum; ++i) {
@@ -384,14 +407,22 @@ int do_main( int argc, char *argv[] )
 	}
 
 	if (skip >= in_images.size()) {
-		throw create_exception<invalid_argument>( "Try to skip ",  skip, " images, but input set has only ", 
-						in_images.size(), " images.");  
+		throw create_exception<invalid_argument>( "Try to skip ",  skip, 
+							  " images, but input set has only ", 
+							  in_images.size(), " images.");  
 	}
 
 	C3DImageSeries series(in_images.begin() + skip, in_images.end()); 
+	if (preskip > series.size() - 2) 
+		throw create_exception<invalid_argument>( "Try to skip ", preskip, " images th the beginning of a series ", 
+							  series.size(), " of relevant images."); 
+	if (postskip  >= series.size() - preskip)
+		throw create_exception<invalid_argument>( "Try to skip ", postskip, " images at the end of a series ", 
+							  series.size(), " of relevant images"); 
+	
 
 	C3DMyocardPeriodicRegistration mpr(params); 
-	vector<P3DTransformation> transforms = mpr.run(series);
+	vector<P3DTransformation> transforms = mpr.run(series, preskip, postskip);
 
 	if (!reference_index_file.empty()) {
 		ofstream refidxfile(reference_index_file.c_str(), ios_base::out );
diff --git a/src/3dsegment-ahmed.cc b/src/3dsegment-ahmed.cc
index 12349b4..ece9599 100644
--- a/src/3dsegment-ahmed.cc
+++ b/src/3dsegment-ahmed.cc
@@ -97,7 +97,9 @@ CSegment3d::CSegment3d(bool bg_correct, int ncc,
 	_M_nClasses(ncc), 
 	_M_bg_correct(bg_correct), 
 	_M_class_centers(icc),
-	_M_k(k)
+	_M_k(k), 
+	_M_minh(0), 
+	_M_maxh(0)
 {
 }	
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3d80d58..586749b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -107,6 +107,7 @@ DEFEXE(2dtrackpixelmovement mia2d )
 
 DEFCHKEXE(3dlerp mia3d )
 
+DEFEXE(2dmultiimageto3d   mia3d )
 DEFEXE(3dimagestats       mia3d )
 DEFEXE(3dcost             mia3d )
 DEFEXE(3ddistance         mia3d )
diff --git a/src/fluid2d/main.cc b/src/fluid2d/main.cc
index 61914e1..d0d1b15 100644
--- a/src/fluid2d/main.cc
+++ b/src/fluid2d/main.cc
@@ -54,7 +54,7 @@ const SProgramDescription g_description = {
 }; 
 
 inline void register_level(const C2DImage& ModelScale, const C2DImage& RefScale, C2DFVectorfield& Shift,
-			   float regrid_thresh,float epsilon, int level, bool elast, float lambda, float mu,
+			   float regrid_thresh,float epsilon, int level, bool elast, float mu, float lambda, 
 			   C2DInterpolatorFactory& ipfactory)
 {
 	FCopy2DImageToFloatRepn converter;
diff --git a/src/fluid3d/sor_solver.cc b/src/fluid3d/sor_solver.cc
index 38b2fe8..9852017 100644
--- a/src/fluid3d/sor_solver.cc
+++ b/src/fluid3d/sor_solver.cc
@@ -34,7 +34,8 @@ using namespace mia;
 
 TSORSolver::TSORSolver(int _max_steps, float _rel_res, float _abs_res,
 		       float mu, float lambda):
-	TFluidHomogenSolver(_max_steps,_rel_res, _abs_res,mu,lambda)
+	TFluidHomogenSolver(_max_steps,_rel_res, _abs_res,mu,lambda), 
+	d_xy(0)
 {
 }
 
diff --git a/src/fluid3d/vfluid.cc b/src/fluid3d/vfluid.cc
index 5c179ea..f1dfff3 100644
--- a/src/fluid3d/vfluid.cc
+++ b/src/fluid3d/vfluid.cc
@@ -80,7 +80,11 @@ TFluidReg::TFluidReg(const TFluidRegParams& params,TLinEqnSolver *_solver, const
 	my(params.My),
 	Start(0,0,0),
 	End(params.source->get_size()),
+	u(nullptr), 
+	delta(1.0),           // step size
+	mismatch(numeric_limits<float>::max()), 
 	matter_threshold(params.matter_threshold),
+	B(nullptr), 
 	solver(_solver),
 	initialStepsize(params.InitialStepsize),
 	ipf(_ipf)
diff --git a/src/raw2image.cc b/src/raw2image.cc
index 33ab672..ad19caa 100644
--- a/src/raw2image.cc
+++ b/src/raw2image.cc
@@ -204,8 +204,12 @@ int do_main(int argc, char *argv[])
 		throw invalid_argument("scale takes exactly 2 parameters");
 
 	C2DImageVector out_images;
-	fseek(in_file, skip, SEEK_SET);
-	out_images.push_back(read_image(in_file, pixel_type, size, scale, high_endian));
+	if (fseek(in_file, skip, SEEK_SET) == 0) 
+		out_images.push_back(read_image(in_file, pixel_type, size, scale, high_endian));
+	else 
+		throw create_exception<invalid_argument>("Skipping ", skip, " bytes of file '", 
+							 in_filename, "' failed:", strerror(errno)); 
+							 
 
 	return !imageio.save(out_filename, out_images);
 }
diff --git a/src/raw2volume.cc b/src/raw2volume.cc
index 3ec5460..337c1d8 100644
--- a/src/raw2volume.cc
+++ b/src/raw2volume.cc
@@ -180,9 +180,12 @@ int do_main(int argc, char *argv[])
 	C3DFVector fscale(scale);
 
 	C3DImageVector out_images;
-	fseek(in_file, skip, SEEK_SET);
-	out_images.push_back(read_image(in_file, pixel_type, bsize, fscale, high_endian));
-
+	if (fseek(in_file, skip, SEEK_SET) == 0) 
+		out_images.push_back(read_image(in_file, pixel_type, bsize, fscale, high_endian));
+	else 
+		throw create_exception<invalid_argument>("Skipping ", skip, " bytes of file '", 
+							 in_filename, "' failed:", strerror(errno)); 
+	
 	return !imageio.save(out_filename, out_images);
 }
 
diff --git a/addons/CMakeLists.txt b/test/CMakeLists.txt
similarity index 82%
copy from addons/CMakeLists.txt
copy to test/CMakeLists.txt
index db0fd88..10ddc94 100644
--- a/addons/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -16,9 +16,7 @@
 # along with this program; if not, see <http://www.gnu.org/licenses/>.
 #
 
-INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}")
+NEW_TEST(minimizer miacore)
+
+NEW_TEST(ioplugins mia3d)
 
-ADD_SUBDIRECTORY(dicom   )
-ADD_SUBDIRECTORY(openexr )
-ADD_SUBDIRECTORY(vtk   )
-ADD_SUBDIRECTORY(vistaio )
diff --git a/test/test_ioplugins.cc b/test/test_ioplugins.cc
new file mode 100644
index 0000000..a8e53ba
--- /dev/null
+++ b/test/test_ioplugins.cc
@@ -0,0 +1,210 @@
+/* -*- mia-c++  -*-
+ *
+ * This file is part of MIA - a toolbox for medical image analysis 
+ * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
+ *
+ * MIA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIA; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+
+#include <mia/internal/autotest.hh>
+
+#include <mia/2d/imageio.hh>
+#include <mia/3d/imageio.hh>
+
+
+using namespace std; 
+using namespace mia; 
+PrepareTestPluginPath g_prepare_pluginpath; 
+
+
+template <typename Handler> 
+struct PluginMapFixture {
+	typedef vector<pair<string, string>> Expectmap; 
+
+	void test_plugin_from_name(const Expectmap& map) const; 
+	void test_suffix_from_name_or_suffix(const Expectmap& map) const; 
+	
+}; 
+
+BOOST_FIXTURE_TEST_CASE( test_2d_plugin_mapping, PluginMapFixture<C2DImageIOPluginHandler> )
+{
+	
+	Expectmap test_filenames;
+	Expectmap test_prefsuffix;
+
+	test_filenames.push_back(make_pair("test.BMP", "bmp")); 
+	test_filenames.push_back(make_pair("test.bmp", "bmp")); 
+
+	test_prefsuffix.push_back(make_pair("bmp", "bmp")); 
+	test_prefsuffix.push_back(make_pair("BMP", "BMP")); 
+	
+#ifdef HAVE_DCMTK 
+	test_filenames.push_back(make_pair("test.dcm", "dicom")); 
+	test_filenames.push_back(make_pair("test.DCM", "dicom")); 
+
+	test_prefsuffix.push_back(make_pair("dicom", "dcm")); 
+
+	test_prefsuffix.push_back(make_pair("dcm", "dcm")); 
+
+#endif 
+
+#ifdef HAVE_VISTAIO
+	test_filenames.push_back(make_pair("test.v", "vista")); 
+	test_filenames.push_back(make_pair("test.V", "vista")); 
+	test_filenames.push_back(make_pair("test.vista", "vista")); 
+	test_filenames.push_back(make_pair("test.VISTA", "vista")); 
+
+	test_prefsuffix.push_back(make_pair("vista", "v")); 
+	test_prefsuffix.push_back(make_pair("v", "v")); 
+#endif 
+
+#ifdef HAVE_OPENEXR
+	test_filenames.push_back(make_pair("test.exr", "exr")); 
+	test_filenames.push_back(make_pair("test.EXR", "exr")); 
+
+	test_prefsuffix.push_back(make_pair("exr", "exr")); 
+#endif 
+
+#ifdef HAVE_PNG
+	test_filenames.push_back(make_pair("test.png", "png")); 
+	test_filenames.push_back(make_pair("test.PNG", "png")); 
+
+	test_prefsuffix.push_back(make_pair("png", "png")); 
+#endif 
+
+#ifdef HAVE_TIFF
+	test_filenames.push_back(make_pair("test.tif", "tif")); 
+	test_filenames.push_back(make_pair("test.TIF","tif")); 
+	test_filenames.push_back(make_pair("test.tiff", "tif")); 
+	test_filenames.push_back(make_pair("test.TIFF","tif")); 
+
+	test_prefsuffix.push_back(make_pair("tif", "tif")); 
+	test_prefsuffix.push_back(make_pair("tiff", "tiff")); 
+#endif 
+
+#ifdef HAVE_JPG
+	test_filenames.push_back(make_pair("test.jpg", "jpg")); 
+	test_filenames.push_back(make_pair("test.JPG", "jpg")); 
+	test_filenames.push_back(make_pair("test.jpeg", "jpg")); 
+	test_filenames.push_back(make_pair("test.JPEG", "jpg")); 
+
+	test_prefsuffix.push_back(make_pair("jpg", "jpg")); 
+	test_prefsuffix.push_back(make_pair("jpeg", "jpeg")); 
+#endif 
+
+	test_plugin_from_name(test_filenames); 
+	test_suffix_from_name_or_suffix(test_prefsuffix); 
+
+}
+
+
+BOOST_FIXTURE_TEST_CASE( test_3d_plugin_mapping, PluginMapFixture<C3DImageIOPluginHandler> )
+{
+	Expectmap test_filenames;
+	Expectmap test_prefsuffix;
+
+#ifdef HAVE_VISTAIO
+	test_filenames.push_back(make_pair("test.v", "vista")); 
+	test_filenames.push_back(make_pair("test.V", "vista")); 
+	test_filenames.push_back(make_pair("test.vista", "vista")); 
+	test_filenames.push_back(make_pair("test.VISTA", "vista")); 
+
+	test_prefsuffix.push_back(make_pair("vista", "v")); 
+	test_prefsuffix.push_back(make_pair("v", "v")); 
+	test_prefsuffix.push_back(make_pair("V", "V")); 
+#endif 
+
+#ifdef HAVE_DCMTK 
+	test_filenames.push_back(make_pair("test.dcm", "dicom")); 
+	test_filenames.push_back(make_pair("test.DCM", "dicom")); 
+
+	test_prefsuffix.push_back(make_pair("test.dicom", "dcm")); 
+	test_prefsuffix.push_back(make_pair("test.dcm", "dcm")); 
+
+#endif 
+
+	test_filenames.push_back(make_pair("test.hdr", "analyze")); 
+	test_filenames.push_back(make_pair("test.HDR", "analyze")); 
+
+	test_prefsuffix.push_back(make_pair("analyze", "hdr")); 
+	
+	test_filenames.push_back(make_pair("test.vff", "vff")); 
+	test_filenames.push_back(make_pair("test.VFF", "vff")); 
+
+	test_prefsuffix.push_back(make_pair("vff", "vff")); 
+
+	test_filenames.push_back(make_pair("test.inr", "inria")); 
+	test_filenames.push_back(make_pair("test.INR", "inria")); 
+
+	test_prefsuffix.push_back(make_pair("inria", "inr")); 
+
+#ifdef HAVE_HDF5
+	test_filenames.push_back(make_pair("test.h5", "hdf5")); 
+	test_filenames.push_back(make_pair("test.H5", "hdf5")); 
+
+	test_prefsuffix.push_back(make_pair("hdf5", "h5")); 
+#endif 
+	
+
+#ifdef HAVE_VTK
+	test_filenames.push_back(make_pair("test.mhd", "mhd")); 
+	test_filenames.push_back(make_pair("test.MHD", "mhd")); 
+	test_filenames.push_back(make_pair("test.mha", "mhd")); 
+	test_filenames.push_back(make_pair("test.MHA", "mhd")); 
+
+	test_prefsuffix.push_back(make_pair("mhd", "mhd")); 
+	
+	test_filenames.push_back(make_pair("test.vtk", "vtk")); 
+	test_filenames.push_back(make_pair("test.VTK", "vtk")); 
+	test_filenames.push_back(make_pair("test.vtkimage", "vtk")); 
+	test_filenames.push_back(make_pair("test.VTKIMAGE", "vtk")); 
+
+	test_prefsuffix.push_back(make_pair("vtk", "vtk")); 
+
+	test_filenames.push_back(make_pair("test.VTI", "vti")); 
+	test_filenames.push_back(make_pair("test.vti", "vti")); 
+
+	test_prefsuffix.push_back(make_pair("vti", "vti")); 
+#endif 
+	test_plugin_from_name(test_filenames); 
+}
+
+
+template <typename Handler> 
+void PluginMapFixture<Handler>::test_plugin_from_name(const Expectmap& map) const
+{
+	const auto& io = Handler::instance(); 
+	for_each(map.begin(), map.end(), 
+		 [&io](const pair<string, string>& p) {
+			 const auto& plugin = io.preferred_plugin(p.first); 
+			 BOOST_CHECK_EQUAL(string(plugin.get_name()), p.second); 
+		 }); 
+	
+}
+
+template <typename Handler> 
+void PluginMapFixture<Handler>::test_suffix_from_name_or_suffix(const Expectmap& map) const
+{
+	const auto& io = Handler::instance(); 
+	for_each(map.begin(), map.end(), 
+		[&io](const pair<string, string>& p) {
+			 cvdebug() << "Test '" << p.first << "\n"; 
+			 BOOST_CHECK_EQUAL(io.get_preferred_suffix(p.first), p.second); 
+		 });
+
+}
diff --git a/test/test_minimizer.cc b/test/test_minimizer.cc
new file mode 100644
index 0000000..3a896ce
--- /dev/null
+++ b/test/test_minimizer.cc
@@ -0,0 +1,191 @@
+/* -*- mia-c++  -*-
+ *
+ * This file is part of MIA - a toolbox for medical image analysis 
+ * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
+ *
+ * MIA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIA; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#define BOOST_TEST_MODULE MINIMIZER_TEST
+
+#include <config.h>
+
+#include <mia/internal/autotest.hh>
+
+#include <mia/core/minimizer.hh>
+#include <mia/core/cmdlineparser.hh>
+#include <mia/core/msgstream.hh>
+
+
+
+using namespace std; 
+using namespace mia; 
+using namespace boost;
+namespace bfs=::boost::filesystem; 
+
+PrepareTestPluginPath g_prepare_pluginpath; 
+
+
+void compare_sets(const set< string >& plugins, const set<string>& test_data)
+{
+	BOOST_CHECK_EQUAL(plugins.size(), test_data.size()); 
+	for (auto p = plugins.begin(); p != plugins.end(); ++p) {
+		BOOST_CHECK_MESSAGE(test_data.find(*p) != test_data.end(), "unexpected plugin '" << *p << "' found"); 
+	}
+	
+	for (auto p = test_data.begin(); p != test_data.end(); ++p)
+		BOOST_CHECK_MESSAGE(plugins.find(*p) != plugins.end(), "expected plugin '" << *p << "' not found"); 
+}
+
+
+class CMinimizerMock : public CMinimizer {
+	
+	
+private: 
+	int do_run(CDoubleVector& x);
+}; 
+
+
+class CProblemMock : public CMinimizer::Problem {
+private: 
+	virtual double  do_f(const CDoubleVector& x); 
+	virtual void    do_df(const CDoubleVector& x, CDoubleVector&  g); 
+	virtual double  do_fdf(const CDoubleVector& x, CDoubleVector&  g); 
+	virtual size_t do_size() const; 
+}; 
+
+
+const char *minimizer_property = "CMinimizerMock"; 
+
+
+BOOST_AUTO_TEST_CASE( test_load_minimizer_plugins )	
+{
+
+	set<string> test_data = { "gdsq", "gsl"};
+
+#ifdef HAVE_NLOPT
+       test_data.insert("nlopt"); 
+#endif  
+	compare_sets(CMinimizerPluginHandler::instance().get_set(), test_data); 
+}
+
+BOOST_AUTO_TEST_CASE( test_missing_property_throws )
+{
+	CMinimizer::PProblem problem(new CProblemMock); 
+	CMinimizerMock minimizer; 
+	
+	minimizer.add(minimizer_property); 
+	minimizer.set_problem(problem); 
+
+	CDoubleVector x(problem->size()); 
+	BOOST_CHECK_THROW(minimizer.run(x), invalid_argument); 
+	
+}
+
+BOOST_AUTO_TEST_CASE( test_test_function_calls )
+{
+	CMinimizer::PProblem problem(new CProblemMock); 
+	CMinimizerMock minimizer; 
+	minimizer.set_problem(problem); 
+	CDoubleVector x(problem->size()); 
+	fill(x.begin(), x.end(), 10.0); 
+	BOOST_REQUIRE(minimizer.run(x) == 0); 
+	
+	
+}
+
+BOOST_AUTO_TEST_CASE( test_test_function_calls_2 )
+{
+	CMinimizer::PProblem problem(new CProblemMock); 
+	CMinimizerMock minimizer; 
+	minimizer.set_problem(problem); 
+	CDoubleVector x(problem->size()); 
+	fill(x.begin(), x.end(), 10.0); 
+	
+	CDoubleVector g(problem->size()); 
+
+	BOOST_CHECK_CLOSE(problem->f(x), 100.0, 0.0001); 
+	BOOST_CHECK_CLOSE(problem->fdf(x, g), 100.0, 0.0001); 
+	
+	for (size_t i = 0; i < problem->size(); ++i) {
+		BOOST_CHECK_CLOSE(g[i], 2 * x[i], 0.0001);  
+	}
+	problem->df(x, g);	
+	for (size_t i = 0; i < problem->size(); ++i) {
+		BOOST_CHECK_CLOSE(g[i], 2 * x[i], 0.0001);  
+	}
+
+
+	vector<double> vx(problem->size()); 
+	fill(vx.begin(), vx.end(), 10.0); 
+	vector<double> vg(problem->size()); 
+	
+	BOOST_CHECK_CLOSE(problem->f(vx), 100.0, 0.0001); 
+	BOOST_CHECK_CLOSE(problem->fdf(vx, vg), 100.0, 0.0001);
+	
+	for (size_t i = 0; i < problem->size(); ++i) {
+		BOOST_CHECK_CLOSE(vg[i], 2 * vx[i], 0.0001);  
+	}
+	
+	problem->df(vx, vg);
+	for (size_t i = 0; i < problem->size(); ++i) {
+		BOOST_CHECK_CLOSE(vg[i], 2 * vx[i], 0.0001);  
+	}
+
+	
+}
+
+
+int CMinimizerMock::do_run(CDoubleVector& x)
+{
+	// this test minimization is only possible because the 
+	// minimum is the only root 
+	double f; 
+	CDoubleVector g(get_problem().size()); 
+	int niter = 100; 
+	do {
+		f = get_problem().fdf(x, g);
+		for (auto ix = x.begin(), ig = g.begin(); ix != x.end(); ++ix, ++ig) {
+			if (*ig != 0.0) 
+				*ix -= f / *ig; 
+		}
+		--niter; 
+		cvdebug() <<"[" << niter << "]: x = " << x[0] << ", f = " << f <<"\n"; 
+	} while (f > 0.0001 && niter); 
+	
+	return niter > 0 ? 0 : -1; 
+}
+
+double CProblemMock::do_f(const CDoubleVector& x)
+{
+	return inner_product(x.begin(), x.end(), x.begin(), 0.0); 
+}
+
+void   CProblemMock::do_df(const CDoubleVector& x, CDoubleVector&  g)
+{
+	assert(x.size() == g.size()); 
+	transform(x.begin(), x.end(), g.begin(), [](double x) {return 2 * x;}); 
+}
+
+double CProblemMock::do_fdf(const CDoubleVector& x, CDoubleVector&  g)
+{
+	do_df(x, g); 
+	return do_f(x); 
+}
+
+size_t CProblemMock::do_size() const
+{
+	return 1; 
+}

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/mia.git



More information about the debian-med-commit mailing list