[vtkusers] Visualizing K-Means segmentation output 3D

Sara Rolfe smrolfe at u.washington.edu
Wed Oct 27 16:13:17 EDT 2010


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;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101027/8b15b711/attachment.htm>


More information about the vtkusers mailing list