[vtkusers] Visualizing K-Means segmentation output 3D
Bill Lorensen
bill.lorensen at gmail.com
Thu Oct 28 00:27:42 EDT 2010
You will either need to volume render the data or extract isosurfaces
with vtkContourFilter. Converting a volume to polydata will only show
the outside boundary (which is what you are seeing).
Bill
On Wed, Oct 27, 2010 at 4:13 PM, Sara Rolfe <smrolfe at u.washington.edu> wrote:
> Hello,
> I have a 3D image which is the output of
> the itk::ScalarImageKmeansImageFilter. The image contains a surface
> extracted from an object, and the voxels have values evenly distributed
> between 0 and 255, assigned by the k-means algorithm. I would like to
> visualize this surface showing the k-means clusters as patches of different
> colors.
> Currently, I am reading the image using ITK, converting it to a VTK image,
> and using the vtkImageDataGeometryFilter to get polydata. I then display
> the polydata. However, the color of the voxels which are background is dark
> blue, so that I cannot see the rest of the image. Do I need to change the
> color mapping, or is my approach incorrect?
> I converted the image data to polydata because I was following some of the
> VTK display examples. But maybe there is a better way to do this? My code
> is below.
> Thanks,
> Sara
> int main(int argc, char * argv [] )
> {
>
> if( argc < 2 )
> {
> std::cerr << "Missing parameters" << std::endl;
> std::cerr << "Usage: " << argv[0] << " inputImageFilename " << std::endl;
> return 1;
> }
> const unsigned int Dimension = 3;
> typedef signed short InputPixelType;
> typedef itk::Image< InputPixelType, Dimension > InputImageType;
> typedef itk::ImageFileReader< InputImageType > ReaderType;
>
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName( argv[1] );
> reader->Update();
>
> // Obtain center of the input image
> InputImageType::Pointer inputImage = reader->GetOutput();
> InputImageType::SizeType size = inputImage->GetBufferedRegion().GetSize();
> InputImageType::IndexType start =
> inputImage->GetBufferedRegion().GetIndex();
>
> // Create the itk::VTKImageExport
> typedef itk::VTKImageExport< InputImageType > ExportFilter1Type;
> ExportFilter1Type::Pointer itkExporter1 = ExportFilter1Type::New();
> itkExporter1->SetInput( reader->GetOutput() );
>
> // Create the vtkImageImport and connect it to the itk::VTKImageExport
> vtkImageImport* vtkImporter1 = vtkImageImport::New();
> ConnectPipelines(itkExporter1, vtkImporter1);
> vtkImporter1->Update();
>
> // Convert the image to a polydata
> vtkImageDataGeometryFilter * imageDataGeometryFilter =
> vtkImageDataGeometryFilter::New();
> imageDataGeometryFilter->SetInputConnection(vtkImporter1->GetOutputPort());
>
> // Create a renderer, render window, and render window interactor
> vtkRenderer* renderer = vtkRenderer::New();
> vtkRenderWindow* renWin = vtkRenderWindow::New();
> vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>
> renWin->SetSize(500, 500);
> renWin->AddRenderer(renderer);
> iren->SetRenderWindow(renWin);
>
> // Set visualization properties
> renderer->SetBackground(0.4392, 0.5020, 0.5647);
>
> vtkPolyDataMapper * polyMapper = vtkPolyDataMapper::New();
> vtkActor * polyActor = vtkActor::New();
>
> polyActor->SetMapper( polyMapper );
> polyMapper->SetInput( imageDataGeometryFilter->GetOutput() );
> polyMapper->ScalarVisibilityOn();
>
> vtkProperty * property = vtkProperty::New();
> property->SetAmbient(0.1);
> property->SetDiffuse(0.1);
> property->SetSpecular(0.5);
> property->SetColor(1.0,0.0,0.0);
> property->SetLineWidth(2.0);
> property->SetRepresentationToSurface();
>
> polyActor->SetProperty( property );
> renderer->AddActor( polyActor );
>
> // Bring up the render window and begin interaction.
> renderer->ResetCamera();
> renWin->Render();
> iren->Start();
>
> // Release VTK components
> polyActor->Delete();
> vtkImporter1->Delete();
> property->Delete();
> polyMapper->Delete();
> renWin->Delete();
> renderer->Delete();
> iren->Delete();
> imageDataGeometryFilter->Delete();
>
> return 0;
> }
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list