[Insight-users] Region Growing Segmentation to Marching Cubes Implementation

khaled danwar khaled.danwar53 at gmail.com
Mon Aug 29 05:47:54 EDT 2011


I tried out the itk vtk import/export connections to load a 3d image in itk
and then 3d render it in vtk but the same problem reappeared. Below is my
adjusted code and the specific error I get:

Code:

const unsigned int InputDimension3D = 3;
typedef unsigned short OutputPixelType;

typedef itk::Image<OutputPixelType, InputDimension3D> InputImageType3D;
typedef itk::ImageSeriesReader<InputImageType3D> ReaderType3D;

typedef itk::VTKImageExport< InputImageType3D > ExportFilterType;
typedef itk::VTKImageImport< InputImageType3D > ImportFilterType;


//Load the data
ReaderType3D::Pointer reader = ReaderType3D::New();
//we need to make use of GDCMImageIO to assist with reading a series of
DICOM files in a different directory
ImageIOType::Pointer dicomReadIO = ImageIOType::New();
reader->SetImageIO( dicomReadIO );
//get the directory whilst instructing to make use of as much information to
distinguish between DICOM files
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetUseSeriesDetails( true );
nameGenerator->SetInputDirectory( outputDirectory );
//extraxt the filenames
    SeriesIdContainer seriesUID = nameGenerator->GetSeriesUIDs();
    FileNamesContainer fileNames = nameGenerator->GetFileNames(
seriesUID.begin()->c_str() );

    reader->SetFileNames( fileNames );
    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
      }

ExportFilterType::Pointer itkExporter = ExportFilterType::New();
itkExporter->SetInput( reader->GetOutput() );
    //Create the vtkImageImport and connect it to the itk::VTKImageExport
instance.
    vtkImageImport* vtkImporter = vtkImageImport::New();
    ConnectPipelines(itkExporter, vtkImporter);

//Smoothing the edges with gaussian
vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter =
vtkSmartPointer<vtkImageGaussianSmooth>::New();
gaussianSmoothFilter->SetInput(vtkImporter->GetOutput());
//gaussianSmoothFilter->SetInputConnection(vtkImporter->GetOutputPort());
gaussianSmoothFilter->SetRadiusFactor(2);

//Marching Cubes
vtkSmartPointer<vtkMarchingCubes> surface =
vtkSmartPointer<vtkMarchingCubes>::New();
surface->SetInput(gaussianSmoothFilter->GetOutput());
//surface->SetInputConnection(gaussianSmoothFilter->GetOutputPort());
surface->ComputeNormalsOn();
surface->ComputeGradientsOn();

//Create a mapper
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInput(surface->GetOutput());
mapper->SetInputConnection(surface->GetOutputPort());

// Visualize
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

renderer->AddActor(actor);
renderWindow->AddRenderer(renderer);
interactor->SetRenderWindow(renderWindow);

renderWindow->SetSize(800,600);
renderWindow->Render();
interactor->Start();



Error:

ERROR: In C:.....\vtkMarchingCubes.cxx, line 415
vtkMarchingCubes (0000000002F58D40): Cannot contour data of dimension != 3


Thanks for any help




On Sun, Aug 28, 2011 at 1:24 AM, Richard Beare <richard.beare at gmail.com>wrote:

> You can use ITK to load the segmented series as a 3D image and either
> save it to a 3d format and load in vtk, or use the itk to vtk
> connector so to transfer the 3d image object to the vtk part of your
> code. There are examples of this in the InsightApplications suite.
>
> It is also likely, although I haven't checked, that vtk has a dicom
> series reader, enabling it to read all of the dicoms into a 3d object
>
> On Sun, Aug 28, 2011 at 1:07 AM, khaled danwar
> <khaled.danwar53 at gmail.com> wrote:
> > Hello,
> > I wasn't not sure if this request for help was better suited for itk
> users
> > or vtk users, so I just went with itk since most of my code uses itk,
> > hopefully nobody objects and I could still get help from any of you
> > (including vtk users).
> > The lay out of the land is this:
> > 1) for each dicom image I use the confidence connected image filter from
> itk
> > to employ a region based segmentation. Note that I do this for each image
> in
> > turn (ie click on seed points on original image, get it segmented, save
> the
> > file as a new dicom file in a folder) becasue I simply need to for this
> > particular project.
> > 2) once I have all my segmented dicom files in that folder, I intend to
> > (more like 'need to') use the marching cubes algorithm given by vtk so
> that
> > I can render a 3D image of the skull (I'm segmenting ct scans to get the
> > bones alone). This is where my problem is.
> > For this particular 3d Rendering, my code looks a little something like
> > this:
> >
> > //Load the data
> > vtkSmartPointer<vtkDICOMImageReader> reader =
> > vtkSmartPointer<vtkDICOMImageReader>::New();
> > reader->SetDirectoryName(outputDirectory.c_str());
> > reader->Update();
> > //Smoothing the edges with gaussian
> > vtkSmartPointer<vtkImageGaussianSmooth> gaussianSmoothFilter =
> > vtkSmartPointer<vtkImageGaussianSmooth>::New();
> > gaussianSmoothFilter->SetInputConnection(reader->GetOutputPort());
> > gaussianSmoothFilter->SetRadiusFactor(2);
> > //Marching Cubes
> > vtkSmartPointer<vtkMarchingCubes> surface =
> > vtkSmartPointer<vtkMarchingCubes>::New();
> > surface->SetInputConnection(gaussianSmoothFilter->GetOutputPort());
> > surface->ComputeNormalsOn();
> > surface->ComputeGradientsOn();
> > //surface->SetInputConnection(reader->GetOutputPort());
> > //Create a mapper
> > vtkSmartPointer<vtkPolyDataMapper> mapper =
> > vtkSmartPointer<vtkPolyDataMapper>::New();
> > mapper->SetInputConnection(surface->GetOutputPort());
> > // Visualize
> > vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> > actor->SetMapper(mapper);
> > vtkSmartPointer<vtkRenderer> renderer =
> > vtkSmartPointer<vtkRenderer>::New();
> >
> > vtkSmartPointer<vtkRenderWindow> renderWindow =
> > vtkSmartPointer<vtkRenderWindow>::New();
> > renderWindow->AddRenderer(renderer);
> > vtkSmartPointer<vtkRenderWindowInteractor> interactor =
> > vtkSmartPointer<vtkRenderWindowInteractor>::New();
> > interactor->SetRenderWindow(renderWindow);
> > renderer->AddActor(actor);
> >
> > renderWindow->SetSize(800,600);
> > renderWindow->Render();
> > interactor->Start();
> >
> > The problem is that the marching cubes algorithm is complaining that the
> > dicom files holding the segmented images are not of 3D format and so it
> cant
> > render an output that I need. So can anyone help me sort out my need to
> use
> > vtk marching cubes algorithm after I've used itk segmentation on multiple
> > files in turn.
> > Thanks for any help,
> > Khaled
> > _____________________________________
> > 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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110829/1f10cc2d/attachment.htm>


More information about the Insight-users mailing list