[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/multi_impex.hxx | ![]() |
---|
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 2003 by Gunnar Kedenburg */ 00004 /* Cognitive Systems Group, University of Hamburg, Germany */ 00005 /* */ 00006 /* This file is part of the VIGRA computer vision library. */ 00007 /* ( Version 1.2.0, Aug 07 2003 ) */ 00008 /* You may use, modify, and distribute this software according */ 00009 /* to the terms stated in the LICENSE file included in */ 00010 /* the VIGRA distribution. */ 00011 /* */ 00012 /* The VIGRA Website is */ 00013 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00014 /* Please direct questions, bug reports, and contributions to */ 00015 /* koethe@informatik.uni-hamburg.de */ 00016 /* */ 00017 /* THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR */ 00018 /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 00019 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ 00020 /* */ 00021 /************************************************************************/ 00022 00023 00024 #ifndef VIGRA_MULTI_IMPEX_HXX 00025 #define VIGRA_MULTI_IMPEX_HXX 00026 00027 #include <memory> 00028 #include <iomanip> 00029 #include <sstream> 00030 #include <iostream> 00031 #include <string> 00032 #include "vigra/basicimageview.hxx" 00033 #include "vigra/impex.hxx" 00034 #include "vigra/multi_array.hxx" 00035 00036 namespace vigra { 00037 00038 void findImageSequence(const std::string &name_base, 00039 const std::string &name_ext, 00040 std::vector<std::string> & numbers); 00041 00042 /** \addtogroup VolumeImpex Import/export of volume data. 00043 */ 00044 00045 //@{ 00046 00047 /********************************************************/ 00048 /* */ 00049 /* importVolume */ 00050 /* */ 00051 /********************************************************/ 00052 00053 /** \brief Function for importing a 3D volume. 00054 00055 The data are expected to be stored in a by-slice manner, 00056 where the slices are enumerated from <tt>name_base+"[0-9]+"+name_ext</tt>. 00057 <tt>name_base</tt> may contain a path. All slice files with the same name base and 00058 extension are considered part of the same volume. Slice numbers must be non-negative, 00059 but can otherwise start anywhere and need not be successive. Slices will be read 00060 in ascending numerical (not lexicographic) order. All slices must have the 00061 same size. The <tt>volume</tt> will be reshaped to match the count and 00062 size of the slices found. 00063 00064 <b>\#include</b> 00065 "<a href="multi_impex_8hxx-source.html">vigra/multi_impex.hxx</a>" 00066 00067 Namespace: vigra 00068 */ 00069 template <class T, class Allocator> 00070 void importVolume (MultiArray <3, T, Allocator> & volume, 00071 const std::string &name_base, 00072 const std::string &name_ext) 00073 { 00074 std::vector<std::string> numbers; 00075 findImageSequence(name_base, name_ext, numbers); 00076 00077 std::string message("importVolume(): No files matching '"); 00078 message += name_base + "[0-9]+" + name_ext + "' found."; 00079 vigra_precondition(numbers.size() > 0, message.c_str()); 00080 00081 for (unsigned int i = 0; i < numbers.size(); ++i) 00082 { 00083 // build the filename 00084 std::string name = name_base + numbers[i] + name_ext; 00085 00086 // import the image 00087 ImageImportInfo info (name.c_str ()); 00088 00089 // reshape the array according to size of first image 00090 if(i == 0) 00091 { 00092 typedef typename MultiArray <3, T>::difference_type Size; 00093 volume.reshape(Size(info.width(), info.height(), numbers.size())); 00094 } 00095 00096 // generate a basic image view to the current layer 00097 MultiArrayView <2, T> array_view (volume.bindOuter (i)); 00098 BasicImageView <T> view = makeBasicImageView (array_view); 00099 vigra_precondition(view.size() == info.size(), 00100 "importVolume(): image size mismatch."); 00101 00102 importImage (info, destImage(view)); 00103 } 00104 } 00105 00106 00107 /********************************************************/ 00108 /* */ 00109 /* exportVolume */ 00110 /* */ 00111 /********************************************************/ 00112 00113 /** \brief Function for exporting a 3D volume. 00114 00115 The volume is exported in a by-slice manner, where the number of slices equals 00116 the depth of the volume. The file names will be enumerated like 00117 <tt>name_base+"000"+name_ext</tt>, <tt>name_base+"001"+name_ext</tt> etc. 00118 (the actual number of zeros depends on the depth). 00119 00120 <b>\#include</b> 00121 "<a href="multi_impex_8hxx-source.html">vigra/multi_impex.hxx</a>" 00122 00123 Namespace: vigra 00124 */ 00125 template <class T, class Tag> 00126 void exportVolume (MultiArrayView <3, T, Tag> const & volume, 00127 const std::string &name_base, 00128 const std::string &name_ext) 00129 { 00130 00131 const unsigned int depth = volume.shape (2); 00132 int numlen = static_cast <int> (std::ceil (std::log10 ((double)depth))); 00133 for (unsigned int i = 0; i < depth; ++i) 00134 { 00135 00136 // build the filename 00137 std::stringstream stream; 00138 stream << std::setfill ('0') << std::setw (numlen) << i; 00139 std::string name_num; 00140 stream >> name_num; 00141 std::string name = name_base + name_num + name_ext; 00142 00143 // generate a basic image view to the current layer 00144 MultiArrayView <2, T, Tag> array_view (volume.bindOuter (i)); 00145 BasicImageView <T> view = makeBasicImageView (array_view); 00146 00147 // import the image 00148 ImageExportInfo info (name.c_str ()); 00149 exportImage (srcImageRange(view), info); 00150 } 00151 } 00152 00153 //@} 00154 00155 } // namespace vigra 00156 00157 #endif // VIGRA_MULTI_IMPEX_HXX
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|