<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2995" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Verdana><FONT size=2>Hello, Mathieu,</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2></FONT></FONT> </DIV>
<DIV><FONT face=Verdana><FONT size=2>I use ITK CVS GDCM to write DICOM images, 
but the DICOM file </FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>can not be read by several DICOM compatible 
software, such</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>as MIPAV 3.0 (<A 
href="http://mipav.cit.nih.gov">http://mipav.cit.nih.gov</A>) , XMedcon 
0.9.9.3</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>, eFilm 2.0.0, BrainLAB surgery plan 
or Stryker navigation software.</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>But it can be read by MRICro 1.40build 1 
and Irfanview.</FONT></FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV><FONT face=Verdana size=2>My intention is wrote fMRI statistical activation 
images computed by</FONT></DIV>
<DIV><FONT face=Verdana size=2>SPM or AFNI into DICOM images for use in image 
navigation system.</FONT></DIV>
<DIV><FONT face=Verdana size=2>So I use the original DICOM infomation to 
construct the new generated</FONT></DIV>
<DIV><FONT face=Verdana size=2>DICOM image. The DICOM image is in RGB 
color  format.</FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV><FONT face=Verdana size=2>The code is as follows:</FONT></DIV>
<DIV><FONT face=Verdana size=2></FONT> </DIV>
<DIV>#include "itkImageFileReader.h"<BR>#include "itkGDCMImageIO.h"<BR>#include 
"itkGDCMSeriesFileNames.h"<BR>#include "itkImageSeriesReader.h"<BR>#include 
"itkImageSeriesWriter.h"<BR>#include "itkNumericSeriesFileNames.h"<BR>#include 
"itkOrientedImage.h"<BR>#include "itkMetaDataObject.h"<BR>#include 
"itkOrientImageFilter.h"<BR>#include "itkRGBPixel.h"</DIV>
<DIV> </DIV>
<DIV>#include <vector><BR>#include <itksys/SystemTools.hxx></DIV>
<DIV> </DIV>
<DIV>int main( int argc, char* argv[] )<BR>{<BR>  if( argc < 1 
)<BR>    {<BR>    std::cerr << "Usage: " 
<< argv[0] << <BR>      " 
DicomDirectory  OutputDicomDirectory" << 
std::endl;<BR>    return EXIT_FAILURE;<BR>    
}</DIV>
<DIV> </DIV>
<DIV><BR>  typedef itk::RGBPixel<unsigned char>    
RGBPixelType;<BR>  const unsigned int      
Dimension = 3;</DIV>
<DIV> </DIV>
<DIV>  typedef itk::OrientedImage< RGBPixelType, Dimension 
>      RGBImageType;<BR>  typedef 
itk::ImageFileReader< RGBImageType >       
RGBReaderType;</DIV>
<DIV> </DIV>
<DIV>  RGBReaderType::Pointer rgbreader = RGBReaderType::New();</DIV>
<DIV> </DIV>
<DIV>  rgbreader->SetFileName( "E:/RGBfMRIDICOM/3drgb.mhd" );</DIV>
<DIV> </DIV>
<DIV>  try<BR>    {<BR>    
rgbreader->Update();<BR>    }<BR>  catch 
(itk::ExceptionObject &excp)<BR>    {<BR>    
std::cerr << "Exception thrown while writing the image" << 
std::endl;<BR>    std::cerr << excp << 
std::endl;<BR>    return EXIT_FAILURE;<BR>    
}</DIV>
<DIV> </DIV>
<DIV><BR>  typedef signed short    PixelType;<BR>  
</DIV>
<DIV> </DIV>
<DIV>  typedef itk::Image< PixelType, Dimension 
>      ImageType;<BR>  typedef 
itk::ImageSeriesReader< ImageType >     
ReaderType;</DIV>
<DIV> </DIV>
<DIV>  typedef 
itk::GDCMImageIO                        
ImageIOType;<BR>  typedef 
itk::GDCMSeriesFileNames                
NamesGeneratorType;</DIV>
<DIV> </DIV>
<DIV>  ImageIOType::Pointer gdcmIO = ImageIOType::New();<BR>  
NamesGeneratorType::Pointer namesGenerator = NamesGeneratorType::New();</DIV>
<DIV> </DIV>
<DIV>  namesGenerator->SetInputDirectory( "E:/RGBfMRIDICOM/014_3D_SPGR" 
);</DIV>
<DIV> </DIV>
<DIV>  const ReaderType::FileNamesContainer & filenames = 
<BR>                            
namesGenerator->GetInputFileNames();</DIV>
<DIV> </DIV>
<DIV><BR>  unsigned int numberOfFilenames =  
filenames.size();<BR>  std::cout << numberOfFilenames << 
std::endl; <BR>  for(unsigned int fni = 0; fni<numberOfFilenames; 
fni++)<BR>    {<BR>    std::cout << 
"filename # " << fni << " = ";<BR>    std::cout 
<< filenames[fni] << std::endl;<BR>    
}<BR> <BR>  ReaderType::Pointer reader = ReaderType::New();</DIV>
<DIV> </DIV>
<DIV>  reader->SetImageIO( gdcmIO );<BR>  reader->SetFileNames( 
filenames );</DIV>
<DIV> </DIV>
<DIV>  try<BR>    {<BR>    
reader->Update();<BR>    }<BR>  catch 
(itk::ExceptionObject &excp)<BR>    {<BR>    
std::cerr << "Exception thrown while writing the image" << 
std::endl;<BR>    std::cerr << excp << 
std::endl;<BR>    return EXIT_FAILURE;<BR>    
}</DIV>
<DIV> </DIV>
<DIV><BR> </DIV>
<DIV>  typedef 
itk::GDCMImageIO                        
ImageIOType;<BR> </DIV>
<DIV> </DIV>
<DIV>  ImageIOType::Pointer rgbgdcmIO = ImageIOType::New();</DIV>
<DIV> </DIV>
<DIV>  const char * outputDirectory = "E:/RGBfMRIDICOM/outputrgb";</DIV>
<DIV> </DIV>
<DIV>  itksys::SystemTools::MakeDirectory( outputDirectory );</DIV>
<DIV> </DIV>
<DIV><BR>  typedef itk::RGBPixel<unsigned char>    
OutputPixelType;<BR>  const unsigned int      
OutputDimension = 2;</DIV>
<DIV> </DIV>
<DIV>  typedef itk::OrientedImage< OutputPixelType, OutputDimension 
>    Image2DType;</DIV>
<DIV> </DIV>
<DIV>  typedef itk::ImageSeriesWriter< 
<BR>                         
RGBImageType, Image2DType >  SeriesWriterType;</DIV>
<DIV> </DIV>
<DIV>  typedef 
itk::NumericSeriesFileNames                
NamesGeneratorType2;<BR>  NamesGeneratorType2::Pointer namesGenerator2 = 
NamesGeneratorType2::New();</DIV>
<DIV> </DIV>
<DIV>  itk::MetaDataDictionary & dict = 
gdcmIO->GetMetaDataDictionary();<BR>  std::string tagkey, 
value;<BR>  tagkey = "0008|0060"; // Modality<BR>  value = 
"MRI";<BR>  itk::EncapsulateMetaData<std::string>(dict, tagkey, value 
);<BR>  tagkey = "0008|0008"; // Image Type<BR>  value = 
"DERIVED\\SECONDARY";<BR>  
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);<BR>  
tagkey = "0008|0064"; // Conversion Type<BR>  value = "WSD";<BR>  
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</DIV>
<DIV> </DIV>
<DIV>  tagkey = "0010|0010";  // Patient's Name<BR>  value  
= "fMRI result";<BR>  itk::EncapsulateMetaData<std::string>(dict, 
tagkey, value);</DIV>
<DIV> </DIV>
<DIV><BR>  tagkey = "0008|0070"; // Manufacturer<BR>  value  = 
"Alekta Medical Instruments Co., Ltd.";<BR>  
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</DIV>
<DIV> </DIV>
<DIV><BR>  tagkey = "0010|0020"; // Patient ID<BR>  value  = 
"12343567890";<BR>  itk::EncapsulateMetaData<std::string>(dict, 
tagkey, value);</DIV>
<DIV> </DIV>
<DIV>  <BR>  tagkey = "0008|0080"; //Institution Name<BR>  
value  = "Alekta Medical Instruments Co. Ltd.";<BR>  
itk::EncapsulateMetaData<std::string>(dict, tagkey, value);</DIV>
<DIV> </DIV>
<DIV>  tagkey = "0008|0090";<BR>  value  = "Jia 
Fucang";<BR>  itk::EncapsulateMetaData<std::string>(dict, tagkey, 
value);</DIV>
<DIV> </DIV>
<DIV><BR>  SeriesWriterType::Pointer seriesWriter = 
SeriesWriterType::New();</DIV>
<DIV> </DIV>
<DIV>  RGBImageType::Pointer image = rgbreader->GetOutput();</DIV>
<DIV> </DIV>
<DIV>  RGBImageType::DirectionType direction;<BR>  direction(0,0) = 1; 
<BR>  direction(0,1) = 0;<BR>  direction(0,2) = 0;<BR>  
direction(1,0) = 0;<BR>  direction(1,1) = 1;<BR>  direction(1,2) = 
0;<BR>  direction(2,0) = 0;<BR>  direction(2,1) = 0;<BR>  
direction(2,2) = 1;<BR> <BR>  image->SetDirection(direction);</DIV>
<DIV> </DIV>
<DIV>  image->Update();<BR>  </DIV>
<DIV> </DIV>
<DIV>   
itk::OrientImageFilter<RGBImageType,RGBImageType>::Pointer orienter 
=<BR>     
itk::OrientImageFilter<RGBImageType,RGBImageType>::New();<BR>   
orienter->UseImageDirectionOn();<BR>   
orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RAI);<BR>   
orienter->SetInput(image);<BR>   orienter->Update();</DIV>
<DIV> </DIV>
<DIV><BR>  seriesWriter->SetInput( orienter->GetOutput() );<BR>  
seriesWriter->SetImageIO( rgbgdcmIO );<BR>  
seriesWriter->SetMetaDataDictionaryArray( 
<BR>                        
reader->GetMetaDataDictionaryArray() );</DIV>
<DIV> </DIV>
<DIV>  RGBImageType::RegionType region = <BR>     
rgbreader->GetOutput()->GetLargestPossibleRegion();</DIV>
<DIV> </DIV>
<DIV>  RGBImageType::IndexType start = region.GetIndex();<BR>  
RGBImageType::SizeType  size  = region.GetSize();</DIV>
<DIV> </DIV>
<DIV><BR>  std::string format = outputDirectory;<BR>  <BR>  
format += "/%04d.dcm";<BR>  <BR>  namesGenerator2->SetSeriesFormat( 
format.c_str() );</DIV>
<DIV> </DIV>
<DIV>  namesGenerator2->SetStartIndex( start[2] + 1 );<BR>  
namesGenerator2->SetEndIndex( start[2] + size[2] );<BR>  
namesGenerator2->SetIncrementIndex( 1 );</DIV>
<DIV> </DIV>
<DIV><BR>  seriesWriter->SetFileNames( 
namesGenerator2->GetFileNames() );</DIV>
<DIV> </DIV>
<DIV>  <BR>  try<BR>    {<BR>    
seriesWriter->Update();<BR>    }<BR>  catch( 
itk::ExceptionObject & excp )<BR>    {<BR>    
std::cerr << "Exception thrown while writing the series " << 
std::endl;<BR>    std::cerr << excp << 
std::endl;<BR>    return EXIT_FAILURE;<BR>    
}</DIV>
<DIV> </DIV>
<DIV><BR>  return 0;<BR>}</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=Verdana><FONT size=2>
<DIV><FONT face=Verdana><FONT size=2>I attached a DICOM file, if any other 
images are needed, I can upload them.</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2></FONT></FONT> </DIV>
<DIV><FONT face=Verdana><FONT size=2>Thank you for any 
hints.</FONT></FONT></DIV>
<DIV> </DIV></FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>Best,</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2>Fucang</FONT></FONT></DIV>
<DIV><FONT face=Verdana><FONT size=2></FONT> </DIV></FONT></BODY></HTML>