7 #include "fwItkIO/JpgImageWriter.hpp" 9 #include "fwItkIO/helper/ProgressItkToFw.hpp" 10 #include "fwItkIO/itk.hpp" 12 #include <fwCore/base.hpp> 14 #include <fwData/Composite.hpp> 15 #include <fwData/Image.hpp> 16 #include <fwData/Integer.hpp> 17 #include <fwData/TransferFunction.hpp> 19 #include <fwDataIO/writer/registry/macros.hpp> 21 #include <fwDataTools/fieldHelper/Image.hpp> 22 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp> 24 #include <fwTools/Dispatcher.hpp> 25 #include <fwTools/DynamicTypeKeyTypeMapping.hpp> 26 #include <fwTools/IntrinsicTypes.hpp> 28 #include <boost/filesystem.hpp> 30 #include <itkImageSeriesWriter.h> 31 #include <itkIntensityWindowingImageFilter.h> 32 #include <itkJPEGImageIOFactory.h> 33 #include <itkNumericSeriesFileNames.h> 43 ::
fwData::location::enableFolder< ::
fwDataIO::writer::IObjectWriter >(this)
50 JpgImageWriter::~JpgImageWriter()
62 ::itk::JPEGImageIOFactory::RegisterOneFactory();
66 std::string m_filename;
67 ::fwData::Image::csptr m_dataImage;
68 ::fwItkIO::JpgImageWriter::sptr m_fwWriter;
73 template<
class PIXELTYPE>
76 OSLM_DEBUG(
"itk::ImageSeriesWriter with PIXELTYPE "<< fwTools::DynamicType::string<PIXELTYPE>() );
78 ::fwData::Image::csptr image = param.m_dataImage;
87 typename itk::ImageIOBase::Pointer imageIOWrite = itk::ImageIOFactory::CreateImageIO(
"image.jpg",
88 itk::ImageIOFactory::WriteMode);
89 assert( imageIOWrite.IsNotNull() );
92 typedef itk::Image< PIXELTYPE, 3> itkImageType;
93 typedef itk::Image< unsigned char, 2 > Image2DType;
94 typedef typename itk::ImageSeriesWriter< itkImageType, Image2DType > WriterType;
95 typename WriterType::Pointer writer = WriterType::New();
98 itk::LightProcessObject::Pointer castHelper = (itk::LightProcessObject*)(imageIOWrite.GetPointer());
99 assert( castHelper.IsNotNull() );
100 Progressor progress(castHelper, param.m_fwWriter, param.m_filename);
103 typename itkImageType::Pointer itkImage = ::fwItkIO::itkImageFactory<itkImageType>( image );
105 typedef ::itk::IntensityWindowingImageFilter< itkImageType, itkImageType > RescaleFilterType;
106 typename RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
109 ::fwData::Composite::sptr poolTF;
115 if(iter != poolTF->end())
117 ::fwData::TransferFunction::sptr tf;
118 tf = ::fwData::TransferFunction::dynamicCast(iter->second);
119 min = tf->getWLMinMax().first;
120 max = tf->getWLMinMax().second;
128 rescaleFilter->SetWindowMinimum( min );
129 rescaleFilter->SetWindowMaximum( max );
130 rescaleFilter->SetOutputMinimum( 0 );
131 rescaleFilter->SetOutputMaximum( 255 );
132 rescaleFilter->InPlaceOff();
133 rescaleFilter->SetInput( itkImage );
134 rescaleFilter->Update();
136 writer->SetInput( rescaleFilter->GetOutput() );
138 typedef itk::NumericSeriesFileNames NameGeneratorType;
140 NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
142 std::string format = param.m_filename;
143 format +=
"/%04d.jpg";
144 nameGenerator->SetSeriesFormat( format.c_str() );
145 nameGenerator->SetStartIndex( 1 );
146 nameGenerator->SetEndIndex( image->getSize()[2] );
147 nameGenerator->SetIncrementIndex( 1 );
149 writer->SetFileNames( nameGenerator->GetFileNames() );
151 writer->SetImageIO( imageIOWrite );
160 void JpgImageWriter::write()
162 assert( !m_object.expired() );
163 assert( m_object.lock() );
166 saverParam.m_filename = this->getFolder().string();
167 saverParam.m_dataImage = this->getConcreteObject();
168 saverParam.m_fwWriter = this->getSptr();
169 assert( saverParam.m_dataImage );
172 saverParam.m_dataImage->getPixelType(), saverParam );
177 std::string JpgImageWriter::extension()
static FWDATA_API const std::string s_DEFAULT_TF_NAME
Default transfer function name.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
This namespace fwDataIO contains reader and writer for several framework's data.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
The namespace fwItkIO contains reader, writer and helper for itk image.
IteratorType find(const KeyType &x)
Contains the representation of the data objects used in the framework.
This class defines a composite object.
ContainerType::iterator iterator
#define OSLM_DEBUG(message)