[Insight-users] ImageFileWriter - write different formats at the same time

Brecht Heyde Brecht.Heyde at med.kuleuven.be
Thu Jan 27 13:29:23 EST 2011


Dear ITK users,

I was wondering what the best way would be to write an output image of a certain filter in 2 formats, e.g. .mhd and .png (for fast viewing purposes in 2D).

I tried using the ImageSeriesWriter but without any result so far. It is templated over the inputimage and the outputimage.
In the normal use the outputimage has one dimension less and the ->SetFileNames(FileNamesContainer) expects N names to be inserted where N stands for the number of slices you would like to write down.

As expected, this code snippet will not work:

---
typedef itk::ImageSeriesWriter<ImageType,ImageType> SeriesWriterType;
SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
seriesWriter->SetInput(filter->GetOutput());
	
std::vector<std::string> fileNamesContainer;
fileNamesContainer.insert(fileNamesContainer.begin(),outputFileName+"translate1020.png");
fileNamesContainer.insert(fileNamesContainer.begin(),outputFileName+"translate1020.mhd");
seriesWriter->SetFileNames(fileNamesContainer);
try{
	seriesWriter->Update();
}
catch(itk::ExceptionObject & err){
	std::cerr << "Exception caught: " << err;
}
---
The error is 
Description: itk::ERROR: ImageSeriesWriter(00C88990): The number of filenames passed is 2 but 1 were expected.

Any alternatives apart from initializing seperate writers, each with the correct output type?

Best regards,
Brecht


More information about the Insight-users mailing list