template<typename ImageType>
typename ImageType::Pointer readImage(const std::vector<std::string> & filenames, const bool verbose=false);
template<class ImageType>
-void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false);
+void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false, const bool compression=false);
// template<class ImageType>
// void writeConstImage(const typename ImageType::ConstPointer image, const std::string & filename, const bool verbose=false);
template<class ImageType>
-void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false);
+void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false, const bool compression=false);
//--------------------------------------------------------------------
// Read/print image header
//--------------------------------------------------------------------
template<class ImageType>
-void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose)
+void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose, const bool compression)
{
- typedef itk::ImageFileWriter<ImageType> WriterType;
- typename WriterType::Pointer writer = WriterType::New();
- writer->SetFileName(filename.c_str());
- writer->SetInput(image);
- if (verbose) {
- std::cout << "Writing [" << filename << "] ... " << std::endl;
- }
- try {
- writer->Update();
- } catch( itk::ExceptionObject & err ) {
- std::cerr << "Exception while writing image [" << filename << "]" << std::endl;
- std::cerr << err << std::endl;
- exit(-1);
- }
+ return writeImage(image.GetPointer(), filename, verbose, compression);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
template<class ImageType>
-void writeImage(const ImageType* image, const std::string & filename, const bool verbose)
+void writeImage(const ImageType* image, const std::string & filename, const bool verbose, const bool compression)
{
typedef itk::ImageFileWriter<ImageType> WriterType;
typename WriterType::Pointer writer = WriterType::New();
writer->SetFileName(filename.c_str());
writer->SetInput(image);
+ writer->SetUseCompression(compression);
if (verbose) {
std::cout << "Writing [" << filename << "] ... " << std::endl;
}
m_FailOnImageTypeError = true;
m_ReadOnDisk = true;
m_WriteOnDisk = true;
+ m_WriteCompression = false;
// m_LastError = "";
// StopOnErrorOn();
SetFilterBase(NULL);
//--------------------------------------------------------------------
+//--------------------------------------------------------------------
+void clitk::ImageToImageGenericFilterBase::EnableWriteCompression(bool b)
+{
+ m_WriteCompression = b;
+}
+//--------------------------------------------------------------------
+
+
//--------------------------------------------------------------------
void clitk::ImageToImageGenericFilterBase::SetInputFilename(const std::string & filename)
{
void clitk::ImageToImageGenericFilterBase::SetNextOutput(typename ImageType::Pointer output)
{
if (m_WriteOnDisk && m_OutputFilenames.size()) {
- clitk::writeImage<ImageType>(output, m_OutputFilenames.front(), m_IOVerbose);
+ clitk::writeImage<ImageType>(output, m_OutputFilenames.front(), m_IOVerbose, m_WriteCompression);
m_OutputFilenames.pop_front();
}
if (m_InputVVImages.size()) //We assume that if a vv image is set as input, we want one as the output
void SetInputFilenames(const std::vector<std::string> & filenames);
void EnableReadOnDisk(bool b);
void EnableWriteOnDisk(bool b);
+ void EnableWriteCompression(bool b);
void SetOutputFilename(const std::string & filename);
void AddOutputFilename(const std::string filename);
void SetOutputFilenames(const std::vector<std::string> & filenames);
protected:
bool m_ReadOnDisk;
bool m_WriteOnDisk;
+ bool m_WriteCompression;
+
/// Call this function to dispatch an output towards the correct sink
template<class ImageType>
void SetNextOutput(typename ImageType::Pointer output);
filter->SetInputFilenames(l);
filter->SetIOVerbose(args_info.verbose_flag);
filter->SetOutputFilename(args_info.output_arg);
+ filter->EnableWriteCompression(args_info.compression_flag);
if (args_info.type_given) filter->SetOutputPixelType(args_info.type_arg);
// Go !
option "output" o "Output image filename" string yes
option "type" t "Output type (float, ushort ...)" string no
option "verbose" v "Verbose" flag off
+option "compression" c "Compress output" flag off