[Insight-users] Help writing RGB 3D file
nicest guy
cedric.ubiq at gmail.com
Wed Jan 20 17:08:55 EST 2010
Thank you,
Following code is what i do in VTK part.
const char* fileName = argv[1];
//const char* fileName = "c:\\image.vtk";
float threshold = atof(argv[2]);
int extractLargest = 1;
extractLargest = atoi(argv[3]);
// data load
vtkSmartPointer<vtkStructuredPointsReader> reader =
vtkSmartPointer<vtkStructuredPointsReader>::New();
reader->SetFileName(fileName);
// create a 3D model using marching cubes
vtkSmartPointer<vtkMarchingCubes> mc =
vtkSmartPointer<vtkMarchingCubes>::New();
mc->SetInputConnection(reader->GetOutputPort());
mc->ComputeNormalsOn();
mc->ComputeGradientsOn();
mc->SetValue(0, threshold); // second value acts as threshold
// to remain largest region
vtkSmartPointer<vtkPolyDataConnectivityFilter> confilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
confilter->SetInputConnection(mc->GetOutputPort());
confilter->SetExtractionModeToLargestRegion();
// create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
if (extractLargest)
{
mapper->SetInputConnection(confilter->GetOutputPort());
}
else
{
mapper->SetInputConnection(mc->GetOutputPort());
}
mapper->ScalarVisibilityOff(); // utilize actor's property I set
// create an actor
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->GetProperty()->SetColor(1,1,1);
actor->SetMapper(mapper);
// create a renderer
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
// create a render window
vtkSmartPointer<vtkRenderWindow> renwin =
vtkSmartPointer<vtkRenderWindow>::New();
renwin->AddRenderer(renderer);
// create an interactor
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renwin);
iren->Initialize();
iren->Start();
Luis Ibanez wrote:
>
> 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
>>
> _____________________________________
> 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
>
>
--
View this message in context: http://old.nabble.com/Help-writing-RGB-3D-file-tp27205635p27249500.html
Sent from the ITK - Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list