[vtkusers] vtkPolydata contour to image

Sara Rolfe smrolfe at u.washington.edu
Sat Mar 12 10:30:38 EST 2011


Hello,

In case it helps to see what I did, I am including the code below.   
However, I suspect this is not the best approach.

Thanks,
Sara

	// Draw contours around the segmented regions
     	vtkSmartPointer<vtkContourFilter> contour =  
vtkSmartPointer<vtkContourFilter>::New();
     	contour->SetInput( vtkImporter->GetOutput() );
     	contour->SetValue(0, 128); // edges of a binary image with  
values 0,255
	contour->Update();
	
	// get list of points from polydata
	vtkPolyData * polyData = contour->GetOutput();
	const unsigned int numberOfPoints = polyData->GetNumberOfCells();
	cout << "Numbers of points: " << numberOfPoints << endl;
	vtkPoints * vtkpoints = polyData->GetCells();

	
	//allocate itk image to be used as a property mask for later region  
merging
	MaskImageType::Pointer propertyMask = MaskImageType::New();	
	propertyMask->SetRegions( inputImage->GetLargestPossibleRegion() );
	propertyMask->SetOrigin( inputImage->GetOrigin() );
	propertyMask->SetSpacing( inputImage->GetSpacing() );
	propertyMask->SetDirection( inputImage->GetDirection() );
	propertyMask->Allocate();
	
	// iterate through image
	double defpoint[3];
	MaskImageType::IndexType index;
	MaskImageType::SpacingType spacing = inputImage->GetSpacing();	
	
	for(unsigned int p =0; p < numberOfPoints; p++)
     {
		vtkpoints->GetCell( p, defpoint );				// get point in polydata mesh  
of surface
		
		index[0] = defpoint[0]/spacing[0];				// convert polydata index to  
field index
		index[1] = defpoint[1]/spacing[1];
		index[2] = defpoint[2]/spacing[2];
		
		propertyMask->SetPixel( index, 255 );
	}

On Mar 11, 2011, at 3:42 PM, Sara Rolfe wrote:

> Hello,
>
> I have a vtkPolydata contour that I'd like to convert into image  
> data.  This is similar to the example here:
> VTK/Examples/Cxx/PolyData/PolyDataContourToImageData
>
> except that I don't want the image contour to be filled.  I thought  
> that I could get around this by using polyData->GetPoints, iterating  
> through the point list, converting to an ITK image index, and  
> assigning the image data value.  However, I get the ridge artifact  
> shown in the image I've attached.
>
> Please let me know if you have any ideas on the optimal method to  
> solve this problem.
>
> Thanks,
> Sara
>
> <Picture 10.png>
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110312/1f0c43b8/attachment.htm>


More information about the vtkusers mailing list