[Insight-users] Help writing RGB 3D file

Luis Ibanez luis.ibanez at kitware.com
Wed Jan 20 15:00:12 EST 2010


Hi Nicest guy,

1)  DICOMImageIO is deprecated.
     Please use GDCMImageIO, as
     illustrated in the example:

     Insight/Examples/IO/
        DicomSeriesReadImageWrite2.cxx


2) Your use of Iterators is a bit strange.

     You should only need to use
      ImageRegionIterators and the
      while loop should just be


inputIt.GoToBegin();
outputIt.GoToBegin();

RGBPixelType p;
p.SetGreen(0);
p.SetBlue(0);

while( !inputIt.IsAtEnd() )
 {
     unsigned char r = inputIt.Get();
     p.SetRed(r);

      outputIt.Set(p);

      ++inputIt;
      ++outputIt;
       progress.CompletedPixel();
}


3)  Note that you can do this a lot easier
     with the new filter:

itkScalarToRGBColormapImageFilter.txx

and the color map:

           itkRedColormapFunctor.h

      You will find this class described in
      the Insight Journal paper:

http://www.insight-journal.org/browse/publication/285



4)  What VTK pipeline are you using
     for visualizing the resulting image  ?




   Regards,


        Luis


---------------------------------------------------
On Sun, Jan 17, 2010 at 9:58 PM, nicest guy <cedric.ubiq at gmail.com> wrote:
>
> Hello,
> I'm trying to develop 3D program.
> I read CT data. and use ITK to save it as ".vtk" file.
> and I use VTk to display it as 3D.
>
> it works fine, VTK shows gray color 3D(of cource, original source(CT) is
> gray image)
>
> But if i try to make RGB 3D image. VTK never drawed colorfully. it just
> drawed gray garbage data.
>
> So i'm wondering whether following ITK source code is wrong or not to write
> RGB 3D data.
>
> ==============[main source]==================
> typedef itk::RGBPixel<unsigned char>   RGBPixelType;
> typedef itk::Image<unsigned short, 3> ImageNDType;
> typedef itk::Image<RGBPixelType, 3> ImageColorNDType;
> typedef itk::ImageSeriesReader<ImageNDType> ReaderType;
> typedef itk::RGBConvertingFilter< ImageNDType, ImageColorNDType >
> RGBConvertingType;
>
> itk::DICOMImageIO2::Pointer io = itk::DICOMImageIO2::New();
>
> // Get the DICOM filenames from the directory
> itk::DICOMSeriesFileNames::Pointer names = itk::DICOMSeriesFileNames::New();
> names->SetDirectory("C:\\CT\\test6");
>
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileNames(names->GetFileNames());
> reader->SetImageIO(io);
>
> reader->Update();
> reader->GetOutput()->Print(std::cout);
>
> RGBConvertingType::Pointer converting = RGBConvertingType::New();
> converting->SetInput(reader->GetOutput());
>
> typedef itk::ImageFileWriter<ImageColorNDType> WriterType;
>
> WriterType::Pointer writer = WriterType::New();
> writer->SetFileName("c:\\Image.vtk");
> writer->SetInput( converting->GetOutput() );
>
> ==============[RGB converting filter source]==================
> inputIt.GoToBegin();
> outputIt.GoToBegin();
>
> while( !inputIt.IsAtEnd() )
> {
>    while( !inputIt.IsAtEndOfLine() )
>      {
>        RGBPixelType p;
>
>             unsigned char r = inputIt.Get();
>        p.SetRed(r);
>        p.SetGreen(0);
>        p.SetBlue(0);
>
>        outputIt.Set(p); //make it red image
>
>            ++inputIt;
>            ++outputIt;
>            progress.CompletedPixel();
>      }
>
>    inputIt.NextLine();
>    outputIt.GoToEndOfLine(); // NextLine() assumes that the
>    outputIt.NextLine();      // iterator is at the end of line.
> }
> --
> View this message in context: http://old.nabble.com/Help-writing-RGB-3D-file-tp27205635p27205635.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list