37 #ifndef VIGRA_MULTI_IMPEX_HXX
38 #define VIGRA_MULTI_IMPEX_HXX
48 #include "basicimageview.hxx"
50 #include "multi_array.hxx"
51 #include "multi_pointoperators.hxx"
78 typedef ImageImportInfo::PixelType PixelType;
90 VIGRA_EXPORT
VolumeImportInfo(
const std::string &baseName,
const std::string &extension);
153 VIGRA_EXPORT PixelType
pixelType()
const;
156 VIGRA_EXPORT
bool isGrayscale()
const;
157 VIGRA_EXPORT
bool isColor()
const;
160 VIGRA_EXPORT
const std::string &name()
const;
162 VIGRA_EXPORT
const std::string &description()
const;
164 template <
class T,
class Str
ide>
168 void getVolumeInfoFromFirstSlice(
const std::string &filename);
175 std::string path_, name_, description_, pixelType_;
177 std::string rawFilename_;
178 std::string baseName_, extension_;
179 std::vector<std::string> numbers_;
214 VIGRA_EXPORT
VolumeExportInfo(
const char * name_base,
const char * name_ext );
215 VIGRA_EXPORT ~VolumeExportInfo();
220 VIGRA_EXPORT VolumeExportInfo &
setFileNameBase(
const char * name_base);
230 VIGRA_EXPORT VolumeExportInfo &
setFileNameExt(
const char * name_ext);
231 VIGRA_EXPORT
const char * getFileNameBase()
const;
232 VIGRA_EXPORT
const char * getFileNameExt()
const;
282 VIGRA_EXPORT VolumeExportInfo &
setFileType(
const char * );
283 VIGRA_EXPORT
const char * getFileType()
const;
289 VIGRA_EXPORT VolumeExportInfo &
setCompression(
const char * type);
290 VIGRA_EXPORT
const char * getCompression()
const;
303 VIGRA_EXPORT VolumeExportInfo &
setPixelType(
const char * );
316 VIGRA_EXPORT VolumeExportInfo & setForcedRangeMapping(
double fromMin,
double fromMax,
317 double toMin,
double toMax);
318 VIGRA_EXPORT
bool hasForcedRangeMapping()
const;
319 VIGRA_EXPORT
double getFromMin()
const;
320 VIGRA_EXPORT
double getFromMax()
const;
321 VIGRA_EXPORT
double getToMin()
const;
322 VIGRA_EXPORT
double getToMax()
const;
327 VIGRA_EXPORT
float getXResolution()
const;
332 VIGRA_EXPORT
float getYResolution()
const;
337 VIGRA_EXPORT
float getZResolution()
const;
375 float m_x_res, m_y_res, m_z_res;
377 std::string m_filetype, m_filename_base, m_filename_ext, m_pixeltype, m_comp;
380 double fromMin_, fromMax_, toMin_, toMax_;
385 template <
class DestIterator,
class Shape,
class T>
387 readVolumeImpl(DestIterator d, Shape
const & shape, std::ifstream & s,
ArrayVector<T> & buffer, MetaInt<0>)
389 s.read((
char*)buffer.
begin(), shape[0]*
sizeof(T));
391 DestIterator dend = d + shape[0];
393 for(; d < dend; ++d, k++)
399 template <
class DestIterator,
class Shape,
class T,
int N>
401 readVolumeImpl(DestIterator d, Shape
const & shape, std::ifstream & s, ArrayVector<T> & buffer, MetaInt<N>)
403 DestIterator dend = d + shape[N];
406 readVolumeImpl(d.begin(), shape, s, buffer, MetaInt<N-1>());
412 template <
class T,
class Str
ide>
413 void VolumeImportInfo::importImpl(MultiArrayView <3, T, Stride> &volume)
const
415 vigra_precondition(this->shape() == volume.shape(),
"importVolume(): Volume must be shaped according to VolumeImportInfo.");
417 if(rawFilename_.size())
419 std::string dirName, baseName;
423 if(_getcwd(oldCWD, 2048) == 0)
426 vigra_fail(
"VolumeImportInfo: Unable to query current directory (getcwd).");
428 if(_chdir(path_.c_str()))
431 vigra_fail(
"VolumeImportInfo: Unable to change to new directory (chdir).");
434 if(getcwd(oldCWD, 2048) == 0)
437 vigra_fail(
"VolumeImportInfo: Unable to query current directory (getcwd).");
439 if(chdir(path_.c_str()))
442 vigra_fail(
"VolumeImportInfo: Unable to change to new directory (chdir).");
446 std::ifstream s(rawFilename_.c_str(), std::ios::binary);
447 vigra_precondition(s.good(),
"RAW file could not be opened");
449 ArrayVector<T> buffer(shape_[0]);
450 detail::readVolumeImpl(volume.traverser_begin(), shape_, s, buffer, vigra::MetaInt<2>());
464 volume.shape() == shape(),
"imported volume has wrong size");
468 for (
unsigned int i = 0; i < numbers_.size(); ++i)
471 std::string name = baseName_ + numbers_[i] + extension_;
474 ImageImportInfo info (name.c_str ());
477 MultiArrayView <2, T, Stride> view (volume.bindOuter (i));
478 vigra_precondition(view.shape() == info.shape(),
479 "importVolume(): the images have inconsistent sizes.");
487 VIGRA_EXPORT
void findImageSequence(
const std::string &name_base,
488 const std::string &name_ext,
489 std::vector<std::string> & numbers);
513 template <
class T,
class Allocator>
515 const std::string &name_base,
516 const std::string &name_ext)
521 info.importImpl(volume);
562 template <
class T,
class Allocator>
564 const std::string &filename)
569 info.importImpl(volume);
585 template <
class T,
class Str
ide>
588 info.importImpl(volume);
594 void setRangeMapping(std::string
const & pixeltype,
595 FindMinMax<T>
const & minmax, ImageExportInfo & info)
597 if(pixeltype ==
"UINT8")
598 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max,
599 (
double)NumericTraits<UInt8>::min(),
600 (
double)NumericTraits<UInt8>::max());
601 else if(pixeltype ==
"INT16")
602 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max,
603 (
double)NumericTraits<Int16>::min(),
604 (
double)NumericTraits<Int16>::max());
605 else if(pixeltype ==
"UINT16")
606 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max,
607 (
double)NumericTraits<UInt16>::min(),
608 (
double)NumericTraits<UInt16>::max());
609 else if(pixeltype ==
"INT32")
610 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max,
611 (
double)NumericTraits<Int32>::min(),
612 (
double)NumericTraits<Int32>::max());
613 else if(pixeltype ==
"UINT32")
614 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max,
615 (
double)NumericTraits<UInt32>::min(),
616 (
double)NumericTraits<UInt32>::max());
617 else if(pixeltype ==
"FLOAT")
618 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max, 0.0, 1.0);
619 else if(pixeltype ==
"DOUBLE")
620 info.setForcedRangeMapping((
double)minmax.min, (
double)minmax.max, 0.0, 1.0);
623 template <
class T,
class Tag>
624 void setRangeMapping(MultiArrayView <3, T, Tag>
const & volume,
625 ImageExportInfo & info, VigraTrueType )
627 std::string pixeltype = info.getPixelType();
628 bool downcast = negotiatePixelType(getEncoderType(info.getFileName(), info.getFileType()),
629 TypeAsString<T>::result(), pixeltype);
633 FindMinMax<T> minmax;
635 setRangeMapping(pixeltype, minmax, info);
639 template <
class T,
class Tag>
640 void setRangeMapping(MultiArrayView <3, T, Tag>
const & volume,
641 ImageExportInfo & info, VigraFalseType )
643 typedef typename T::value_type SrcComponent;
644 std::string pixeltype = info.getPixelType();
645 bool downcast = negotiatePixelType(getEncoderType(info.getFileName(), info.getFileType()),
646 TypeAsString<SrcComponent>::result(), pixeltype);
650 unsigned int bands = volume(0,0,0).size();
651 FindMinMax<SrcComponent> minmax;
652 for(
unsigned int i=0; i<bands; ++i)
654 VectorComponentValueAccessor<T> band(i);
657 setRangeMapping(pixeltype, minmax, info);
683 template <
class T,
class Tag>
687 std::string name = std::string(volinfo.getFileNameBase()) + std::string(volinfo.getFileNameExt());
691 detail::setRangeMapping(volume, info,
typename NumericTraits<T>::isScalar());
693 const unsigned int depth = volume.
shape (2);
695 for (
unsigned int i = 0; i < depth; ++i)
699 std::stringstream stream;
700 stream << std::setfill (
'0') << std::setw (numlen) << i;
701 std::string name_num;
703 std::string name = std::string(volinfo.getFileNameBase()) + name_num + std::string(volinfo.getFileNameExt());
708 info.setFileName(name.c_str ());
714 template <
class T,
class Tag>
716 void exportVolume (MultiArrayView <3, T, Tag>
const & volume,
717 const std::string &name_base,
718 const std::string &name_ext)
720 VolumeExportInfo volinfo(name_base.c_str(), name_ext.c_str());
728 #endif // VIGRA_MULTI_IMPEX_HXX
VolumeExportInfo & setZResolution(float)
VolumeExportInfo & setFileNameBase(const char *name_base)
const difference_type & shape() const
Definition: multi_array.hxx:1602
VolumeExportInfo & setCompression(const char *type)
const_iterator begin() const
Definition: array_vector.hxx:223
Main MultiArray class containing the memory management.
Definition: multi_array.hxx:595
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2756
Two dimensional difference vector.
Definition: diff2d.hxx:185
VolumeExportInfo & setPosition(const Diff2D &pos)
Diff2D getPosition() const
VolumeExportInfo(const char *name_base, const char *name_ext)
std::ptrdiff_t MultiArrayIndex
Definition: multi_iterator.hxx:348
const char * getPixelType() const
void importVolume(MultiArray< 3, T, Allocator > &volume, const std::string &name_base, const std::string &name_ext)
Function for importing a 3D volume.
Definition: multi_impex.hxx:514
VolumeExportInfo & setYResolution(float)
void exportImage(...)
Write an image given a vigra::ImageExportInfo object.
const ICCProfile & getICCProfile() const
linalg::TemporaryMatrix< T > log10(MultiArrayView< 2, T, C > const &v)
Argument object for the function exportVolume().
Definition: multi_impex.hxx:196
TinyVector< float, 3 > Resolution
3D resolution type returned by resolution()
Definition: multi_impex.hxx:87
const char * getPixelType() const
Argument object for the function exportImage().
Definition: imageinfo.hxx:133
Argument object for the function importVolume().
Definition: multi_impex.hxx:75
void importImage(...)
Read the image specified by the given vigra::ImageImportInfo object.
VolumeExportInfo & setPixelType(const char *)
MultiArrayIndex width() const
void exportVolume(MultiArrayView< 3, T, Tag > const &volume, const VolumeExportInfo &volinfo)
Function for exporting a 3D volume.
Definition: multi_impex.hxx:684
Class for fixed size vectors.This class contains an array of size SIZE of the specified VALUETYPE...
Definition: accessor.hxx:939
ImageExportInfo & setPixelType(const char *)
ArrayVector< unsigned char > ICCProfile
Definition: multi_impex.hxx:362
MultiArrayIndex depth() const
MultiArrayIndex height() const
image import and export functions
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:593
ImageExportInfo & setCompression(const char *type)
MultiArrayShape< 3 >::type ShapeType
type of volume size returned by shape()
Definition: multi_impex.hxx:81
ShapeType size_type
provided for backwards-compatibility (deprecated)
Definition: multi_impex.hxx:84
int ceil(FixedPoint< IntBits, FracBits > v)
rounding up.
Definition: fixedpoint.hxx:675
VolumeExportInfo & setFileNameExt(const char *name_ext)
void inspectMultiArray(...)
Call an analyzing functor at every element of a multi-dimensional array.
Resolution resolution() const
PixelType pixelType() const
VolumeExportInfo & setXResolution(float)
VolumeExportInfo & setICCProfile(const ICCProfile &profile)
MultiArrayView< N-M, T, StrideTag > bindOuter(const TinyVector< Index, M > &d) const
Definition: multi_array.hxx:2101
VolumeExportInfo & setFileType(const char *)