[Insight-users] read a meta image and write it to DICOM

Rama Aravind Vorray ramavorray at yahoo.com
Sun Sep 11 19:20:27 EDT 2005


Just type cast the data by yourself
<variable>=(usigned char)<variable>; or operate bit
wise on each number to know what part of that number
you needed.

If you are sure that your data has useful information
within 8bits then just typecast your 'short' to
'unsigned char'. Otherwise if you want to take care of
signed bit also, then you have to work on bit by bit
basis. Like left shifting or right shifting of data
upto the extent you needed or you got your result.

--- ³¯¬FÞm <m9421001 at gmail.com> wrote:

> Thanks for your help.
> But I don't know how to rescale my input data to fit
> within the range
> of the WriteType
> Have any example about this?
> 
> appreciate your kindness.
>                           
>                                                     
> Wordon
> 
> 2005/9/12, Bill Lorensen <wlorens1 at nycap.rr.com>:
> > You can specify any integral type for dicom. The
> problem is your input and
> > output types are not consistent.
> > 
> > You can:
> > 
> > 1) Declare the ImageType for the reader to be
> short. However if your input
> > range exceeds that which a short can hold you will
> have problems.
> > 
> > 2) Declare the WriteType to be signed int.
> However, most dicom images are
> > with short or unsigned short.
> > 
> > 3) Insert a CastImageFilter<ImageType,WriteType>.
> Here you will have the
> > same problems as 1).
> > 
> > 4) Rescale your input data to fit within the range
> of the WriteType.
> > Several options are available.
> > 
> > Bill
> > 
> > At 01:21 PM 9/11/2005, =?BIG5?B?s6+sRt5t?= wrote:
> > >Hi,all ITK user:
> > >
> > >I want to read a meta image(.mhd) and write it to
> DICOM format.
> > >
> > >This is my code for this question:
> > >
> >
>
>========================================================
> > >#include "itkImageFileReader.h"
> > >#include "itkImageFileWriter.h"
> > >#include "itkImage.h"
> > >#include "itkRescaleIntensityImageFilter.h"
> > >#include "itkMetaDataDictionary.h"
> > >#include "itkMetaDataObject.h"
> > >#include "itkGDCMImageIO.h"
> > >
> > >#include <list>
> > >#include <fstream>
> > >
> > >int main(int ac, char* av[])
> > >{
> > >
> > >   if(ac < 3)
> > >     {
> > >     std::cerr << "Usage: " << av[0] << "
> InputMETAFile OutputDICOM\n";
> > >     return EXIT_FAILURE;
> > >     }
> > >
> > >   typedef itk::Image<signed int, 3> ImageType;
> > >
> > >   typedef itk::ImageFileReader< ImageType >
> VolumeReaderType;
> > >
> > >   VolumeReaderType::Pointer reader =
> VolumeReaderType::New();
> > >
> > >   reader->SetFileName( av[1] );
> > >
> > >   try
> > >     {
> > >     reader->Update();
> > >     }
> > >   catch (itk::ExceptionObject & e)
> > >     {
> > >     std::cerr << "exception in file reader " <<
> std::endl;
> > >     std::cerr << e.GetDescription() <<
> std::endl;
> > >     std::cerr << e.GetLocation() << std::endl;
> > >     return EXIT_FAILURE;
> > >     }
> > >
> > >
> > >   typedef itk::GDCMImageIO        ImageIOType;
> > >
> > >   ImageIOType::Pointer gdcmImageIO =
> ImageIOType::New();
> > >
> > >
> > >
> > >   typedef itk::Image<short, 3> WriteType;
> > >   typedef itk::ImageFileWriter<WriteType>      
> Writer1Type;
> > >   Writer1Type::Pointer
> writer1=Writer1Type::New();
> > >
> > >   writer1->SetFileName( av[2] );
> > >   writer1->SetImageIO( gdcmImageIO );
> > >   writer1->SetInput( reader->GetOutput() );
> > >
> > >
> > >   try
> > >     {
> > >     writer1->Update();
> > >     }
> > >   catch (itk::ExceptionObject & e)
> > >     {
> > >     std::cerr << "exception in file writer " <<
> std::endl;
> > >     std::cerr << e.GetDescription() <<
> std::endl;
> > >     std::cerr << e.GetLocation() << std::endl;
> > >     return EXIT_FAILURE;
> > >     }
> > >
> > >   return EXIT_SUCCESS;
> > >
> > >}
> > >
> >
>
>========================================================
> > >I get a error message as follows:
> > >
> > >error C2664: 'SetInput' : cannot convert
> parameter 1 from 'class
> > >itk::Image<int,3> *' to 'const class
> itk::Image<short,3> *'
> > >Types pointed to are unrelated; conversion
> requires reinterpret_cast,
> > >C-style cast or function-style cast
> > >
> > >
> > >My question is:
> > >
> > >what format can specify when I  read a META image
> and write it to DICOM?
> > >_______________________________________________
> > >Insight-users mailing list
> > >Insight-users at itk.org
> > >http://www.itk.org/mailman/listinfo/insight-users
> > 
> >
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Insight-users mailing list