22 #include <itkImageSeriesWriter.h>
23 #include <itkNumericSeriesFileNames.h>
24 #include <itkRescaleIntensityImageFilter.h>
26 #include <itkRGBAPixel.h>
29 template <
class WriterType>
32 if (numberOfImages > 1)
36 std::string finalFileName = baseFileName;
37 std::string::size_type pos = baseFileName.find_last_of(
".", baseFileName.length() - 1);
38 if (pos == std::string::npos)
39 finalFileName.append(
".%d.png");
41 finalFileName.insert(pos,
".%d");
45 numericFileNameWriter->SetEndIndex(numberOfImages);
46 numericFileNameWriter->SetSeriesFormat(finalFileName.c_str());
47 numericFileNameWriter->Modified();
48 writer->SetFileNames(numericFileNameWriter->GetFileNames());
54 writer->SetFileName(baseFileName.c_str());
58 template <
typename TPixel,
unsigned int VImageDimension>
61 typedef itk::Image<TPixel, VImageDimension> TImageType;
63 typedef itk::Image<unsigned char, 3> UCharOutputImage3DType;
64 typedef itk::Image<unsigned short, 3> ShortOutputImage3DType;
65 typedef itk::Image<unsigned char, 2> OutputImage2D_8bitType;
66 typedef itk::Image<unsigned short, 2> OutputImage2D_16bitType;
68 typedef itk::ImageSeriesWriter<UCharOutputImage3DType, OutputImage2D_8bitType> UCharWriterType;
69 typedef itk::ImageSeriesWriter<ShortOutputImage3DType, OutputImage2D_16bitType> ShortWriterType;
71 typedef itk::RescaleIntensityImageFilter<TImageType, UCharOutputImage3DType> UCharRescalerFilterType;
72 typedef itk::RescaleIntensityImageFilter<TImageType, ShortOutputImage3DType> ShortRescalerFilterType;
75 size_t inputTypeSize =
sizeof(TPixel);
76 size_t supportedOutputMaxSize = 1;
79 if (fileName.find(
".png") != std::string::npos || fileName.find(
".tif") != std::string::npos)
81 supportedOutputMaxSize = 2;
85 unsigned int numberOfImages = 1;
86 if (itkImage->GetImageDimension() > 2)
87 numberOfImages = itkImage->GetLargestPossibleRegion().GetSize()[2];
90 sh_rescaler->SetInput(itkImage);
91 sh_rescaler->SetOutputMinimum(0);
92 sh_rescaler->SetOutputMaximum(65535);
95 rescaler->SetInput(itkImage);
96 rescaler->SetOutputMinimum(0);
97 rescaler->SetOutputMaximum(255);
102 if (inputTypeSize == 1)
105 SetOutputNames<UCharWriterType>(writer, fileName, numberOfImages);
106 writer->SetInput(rescaler->GetOutput());
110 else if (inputTypeSize == supportedOutputMaxSize && supportedOutputMaxSize == 2)
113 SetOutputNames<ShortWriterType>(writer, fileName, numberOfImages);
114 writer->SetInput(sh_rescaler->GetOutput());
120 if (supportedOutputMaxSize == 2)
123 SetOutputNames<ShortWriterType>(writer, fileName, numberOfImages);
124 writer->SetInput(sh_rescaler->GetOutput());
130 SetOutputNames<UCharWriterType>(writer, fileName, numberOfImages);
131 writer->SetInput(rescaler->GetOutput());
136 catch (
const itk::ExceptionObject &e)
138 MITK_ERROR <<
"ITK Exception occured: " << e.what();
139 mitkThrow() <<
"Caught ITK exception while writing image with scalar type \n" << e.what();
143 template <
typename TPixel,
unsigned int VImageDimension>
146 typedef itk::Image<TPixel, VImageDimension> TImageType;
147 typedef itk::Image<TPixel, 2> TImageType2D;
149 typedef itk::ImageSeriesWriter<TImageType, TImageType2D> WriterType;
153 unsigned int numberOfImages = 1;
154 if (itkImage->GetImageDimension() > 2)
155 numberOfImages = itkImage->GetLargestPossibleRegion().GetSize()[2];
158 SetOutputNames<WriterType>(writer, fileName, numberOfImages);
160 writer->SetInput(itkImage);
165 catch (
const itk::ExceptionObject &e)
167 MITK_ERROR <<
"ITK Exception occured: " << e.what();
168 mitkThrow() <<
"Caught ITK exception while writing image with composite type \n" << e.what();
172 #define InstantiateAccessFunction__mitkItkPictureWrite(pixelType, dim) \
173 template MITKLEGACYIO_EXPORT void _mitkItkPictureWrite(itk::Image<pixelType, dim> *, const std::string &);
175 #define InstantiateAccessFunction__mitkItkPictureWriteComposite(pixelType, dim) \
176 template MITKLEGACYIO_EXPORT void _mitkItkPictureWriteComposite(itk::Image<pixelType, dim> *, const std::string &);
void SetOutputNames(typename WriterType::Pointer writer, const std::string &baseFileName, unsigned int numberOfImages)
itk::SmartPointer< Self > Pointer
InstantiateAccessFunction(_mitkItkPictureWrite) InstantiateAccessFunctionForFixedPixelType(_mitkItkPictureWriteComposite
#define MITK_ACCESSBYITK_PIXEL_TYPES_SEQ
InstantiateAccessFunctionForFixedPixelType(AccessItkImage,(float)(double)) InstantiateAccessFunctionForIntegralPixelTypes(AccessItkImage) int mitkInstantiateAccessFunctionTest(int
void _mitkItkPictureWriteComposite(itk::Image< TPixel, VImageDimension > *itkImage, const std::string &fileName)
ITK-Like method to be called for writing an image.
void _mitkItkPictureWrite(itk::Image< TPixel, VImageDimension > *itkImage, const std::string &fileName)
ITK-Like method to be called for writing an single-component image using the AccessByItk Macros...
#define MITK_ACCESSBYITK_COMPOSITE_PIXEL_TYPES_SEQ
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.