15 #ifndef __itkCreatePositiveMammogram_h
16 #define __itkCreatePositiveMammogram_h
18 #include <itksys/SystemTools.hxx>
21 #include <itkMetaDataDictionary.h>
22 #include <itkMetaDataObject.h>
25 #include <itkMinimumMaximumImageCalculator.h>
26 #include <itkRescaleIntensityImageFilter.h>
28 #include <itkCastImageFilter.h>
39 void SetTag( itk::MetaDataDictionary &dictionary,
48 DictionaryType::ConstIterator tagItr = dictionary.Find( tagID );
49 DictionaryType::ConstIterator
end = dictionary.End();
53 MetaDataStringType::ConstPointer entryvalue =
54 dynamic_cast<const MetaDataStringType *
>( tagItr->second.GetPointer() );
58 std::string tagValue = entryvalue->GetMetaDataObjectValue();
60 std::cout <<
"Changing tag (" << tagID <<
") "
61 <<
" from: " << tagValue
62 <<
" to: " << newTagValue << std::endl;
64 itk::EncapsulateMetaData<std::string>( dictionary, tagID, newTagValue );
69 std::cout <<
"Setting tag (" << tagID <<
") "
70 <<
" to: " << newTagValue << std::endl;
72 itk::EncapsulateMetaData<std::string>( dictionary, tagID, newTagValue );
82 void ModifyTag( itk::MetaDataDictionary &dictionary,
93 DictionaryType::ConstIterator tagItr = dictionary.Find( tagID );
94 DictionaryType::ConstIterator tagEnd = dictionary.End();
96 if ( tagItr != tagEnd )
98 MetaDataStringType::ConstPointer entryvalue =
99 dynamic_cast<const MetaDataStringType *
>( tagItr->second.GetPointer() );
103 std::string tagValue = entryvalue->GetMetaDataObjectValue();
105 std::cout <<
"Modifying tag (" << tagID <<
") "
106 <<
" from: " << tagValue
107 <<
" to: " << newTagValue << std::endl;
109 itk::EncapsulateMetaData<std::string>( dictionary, tagID, newTagValue );
120 template <
typename TImage >
122 itk::MetaDataDictionary &dictionary,
123 bool flgInvert=
false )
132 DictionaryType::ConstIterator tagInverseItr = dictionary.Find( tagInverse );
133 DictionaryType::ConstIterator tagInverseEnd = dictionary.End();
135 if ( tagInverseItr != tagInverseEnd )
137 MetaDataStringType::ConstPointer entryvalue =
138 dynamic_cast<const MetaDataStringType *
>( tagInverseItr->second.GetPointer() );
143 std::string tagInverseValue = entryvalue->GetMetaDataObjectValue();
145 std::cout <<
"Tag (" << tagInverse
146 <<
") is: " << tagInverseValue << std::endl;
148 std::size_t foundInverse = tagInverseValue.find( strInverse );
149 if (foundInverse != std::string::npos)
152 std::cout <<
"Image is INVERSE - inverting" << std::endl;
153 SetTag( dictionary, tagInverse,
"IDENTITY" );
163 DictionaryType::ConstIterator tagPhotoInterpItr = dictionary.Find( tagPhotoInterpID );
164 DictionaryType::ConstIterator tagPhotoInterpEnd = dictionary.End();
166 if ( tagPhotoInterpItr != tagPhotoInterpEnd )
168 MetaDataStringType::ConstPointer entryvalue =
169 dynamic_cast<const MetaDataStringType *
>( tagPhotoInterpItr->second.GetPointer() );
174 std::string tagPhotoInterpValue = entryvalue->GetMetaDataObjectValue();
176 std::cout <<
"Tag (" << tagPhotoInterpID
177 <<
") is: " << tagPhotoInterpValue << std::endl;
179 std::size_t foundMonochrome1 = tagPhotoInterpValue.find( strMonochrome1 );
180 if (foundMonochrome1 != std::string::npos)
183 std::cout <<
"Image is MONOCHROME1 - inverting" << std::endl;
184 SetTag( dictionary, tagPhotoInterpID,
"MONOCHROME2" );
196 typename InvertFilterType::Pointer invertFilter = InvertFilterType::New();
197 invertFilter->SetInput( image );
199 invertFilter->Update( );
201 image = invertFilter->GetOutput();
202 image->DisconnectPipeline();
212 template <
typename TImage >
214 itk::MetaDataDictionary &dictionary )
216 bool flgPreInvert =
false;
218 itksys_ios::ostringstream
value;
223 typedef itk::Image< float, TImage::ImageDimension >
FloatImageType;
225 typedef itk::MinimumMaximumImageCalculator< TImage > MinimumMaximumImageCalculatorType;
227 typedef itk::CastImageFilter< TImage, FloatImageType > CastFilterType;
231 typedef itk::RescaleIntensityImageFilter< FloatImageType, TImage > RescalerType;
233 DictionaryType::ConstIterator tagItr;
234 DictionaryType::ConstIterator tagEnd;
241 tagItr = dictionary.Find( tagModalityID );
242 tagEnd = dictionary.End();
244 if( tagItr != tagEnd )
246 MetaDataStringType::ConstPointer entryvalue =
247 dynamic_cast<const MetaDataStringType *
>( tagItr->second.GetPointer() );
251 tagModalityValue = entryvalue->GetMetaDataObjectValue();
252 std::cout <<
"Modality Name (" << tagModalityID <<
") "
253 <<
" is: " << tagModalityValue << std::endl;
262 tagItr = dictionary.Find( tagForProcessingID );
263 tagEnd = dictionary.End();
265 if( tagItr != tagEnd )
267 MetaDataStringType::ConstPointer entryvalue =
268 dynamic_cast<const MetaDataStringType *
>( tagItr->second.GetPointer() );
272 tagForProcessingValue = entryvalue->GetMetaDataObjectValue();
273 std::cout <<
"Presentation Intent Type (" << tagForProcessingID <<
") "
274 <<
" is: " << tagForProcessingValue << std::endl;
280 if ( ( ( tagModalityValue ==
std::string(
"CR" ) ) ||
282 ( tagForProcessingValue ==
std::string(
"FOR PROCESSING" ) ) )
284 std::cout <<
"Image is a raw \"FOR PROCESSING\" mammogram - converting"
289 std::cout <<
"Skipping image - does not appear to be a \"FOR PROCESSING\" mammogram"
290 << std::endl << std::endl;
296 typename MinimumMaximumImageCalculatorType::Pointer
297 imageRangeCalculator = MinimumMaximumImageCalculatorType::New();
299 imageRangeCalculator->SetImage( image );
300 imageRangeCalculator->Compute();
305 ModifyTag( dictionary,
"0008|0068",
"FOR PRESENTATION" );
310 itk::EncapsulateMetaData<std::string>(dictionary,
"0028|1040", value.str());
315 itk::EncapsulateMetaData<std::string>(dictionary,
"0028|1041", value.str());
318 ModifyTag( dictionary,
"2050|0020",
"IDENTITY" );
325 tagItr = dictionary.Find( tagPhotoInterpID );
326 tagEnd = dictionary.End();
328 if( tagItr != tagEnd )
330 MetaDataStringType::ConstPointer entryvalue =
331 dynamic_cast<const MetaDataStringType *
>( tagItr->second.GetPointer() );
335 tagPhotoInterpValue = entryvalue->GetMetaDataObjectValue();
336 std::cout <<
"Photometric interportation is (" << tagPhotoInterpID <<
") "
337 <<
" is: " << tagPhotoInterpValue << std::endl;
341 std::size_t found = tagPhotoInterpValue.find(
"MONOCHROME2" );
342 if ( found != std::string::npos )
344 std::cout <<
"Image is \"MONOCHROME2\" so will not be inverted"
349 found = tagPhotoInterpValue.find(
"MONOCHROME1" );
350 if ( found != std::string::npos )
352 ModifyTag( dictionary,
"0028|0004",
"MONOCHROME2" );
358 typename CastFilterType::Pointer castFilter = CastFilterType::New();
359 castFilter->SetInput( image );
360 castFilter->UpdateLargestPossibleRegion();
361 typename FloatImageType::Pointer flImage = castFilter->GetOutput();
365 typename InvertFilterType::Pointer invfilter = InvertFilterType::New();
366 invfilter->SetInput( flImage );
367 invfilter->UpdateLargestPossibleRegion();
368 flImage = invfilter->GetOutput();
369 flImage->DisconnectPipeline();
372 typename LogFilterType::Pointer logfilter = LogFilterType::New();
373 logfilter->SetInput( flImage );
374 logfilter->UpdateLargestPossibleRegion();
376 typename InvertFilterType::Pointer invfilter = InvertFilterType::New();
377 invfilter->SetInput(logfilter->GetOutput());
378 invfilter->UpdateLargestPossibleRegion();
380 flImage = invfilter->GetOutput();
381 flImage->DisconnectPipeline();
386 typename RescalerType::Pointer intensityRescaler = RescalerType::New();
388 intensityRescaler->SetOutputMinimum(
389 static_cast< typename TImage::PixelType >( imageRangeCalculator->GetMinimum() ) );
390 intensityRescaler->SetOutputMaximum(
391 static_cast< typename TImage::PixelType >( imageRangeCalculator->GetMaximum() ) );
393 std::cout <<
"Image output range will be: " << intensityRescaler->GetOutputMinimum()
394 <<
" to " << intensityRescaler->GetOutputMaximum() << std::endl;
396 intensityRescaler->SetInput( flImage );
398 intensityRescaler->UpdateLargestPossibleRegion();
400 image = intensityRescaler->GetOutput();
401 image->DisconnectPipeline();
itk::MetaDataObject< std::string > MetaDataStringType
Definition: niftkAnonymiseDICOMImages.cxx:52
bool ConvertMammogramFromRawToPresentation(typename TImage::Pointer &image, itk::MetaDataDictionary &dictionary)
Convert a raw DICOM mammogram to a presentation version by log inverting it.
Definition: itkCreatePositiveMammogram.h:213
GLenum GLsizei GLenum GLenum const GLvoid * image
Definition: glew.h:4052
Definition: niftkITKAffineResampleImage.cxx:74
void CreatePositiveMammogram(typename TImage::Pointer &image, itk::MetaDataDictionary &dictionary, bool flgInvert=false)
Create a positive version of a DICOM mammogram.
Definition: itkCreatePositiveMammogram.h:121
itk::MetaDataDictionary DictionaryType
Definition: niftkAnonymiseDICOMImages.cxx:51
GLuint GLuint end
Definition: glew.h:1237
void SetTag(itk::MetaDataDictionary &dictionary, std::string tagID, std::string newTagValue)
Definition: itkCreatePositiveMammogram.h:39
Invert intensity of an image.
Definition: itkInvertIntensityBetweenMaxAndMinImageFilter.h:87
GLsizei const GLfloat * value
Definition: glew.h:1833
void ModifyTag(itk::MetaDataDictionary &dictionary, std::string tagID, std::string newTagValue)
Definition: itkCreatePositiveMammogram.h:82
Computes the vcl_log(x) pixel-wise of non-zero intensities leaving zero-valued pixels unchanged...
Definition: itkLogNonZeroIntensitiesImageFilter.h:57
itk::Image< float, 3 > FloatImageType
Definition: niftkKNDoubleWindowBSI.cxx:56
GLsizei const GLcharARB ** string
Definition: glew.h:5194