[vtkusers] Watershed (Volume Rendering) Cropping Problem
Yusuf OEZBEK
nasil122002 at yahoo.de
Mon Mar 29 06:07:23 EDT 2010
Hello All.
I have a problem with to cut (cropping) a 3D object, which I produced by the segmentation-method “watershed”. In the beginning I read the DICOM (. dcm) images with itkImageSeriesReader then I run watershed algorithm, in order to connect itk with vtk and a 3D object produce, I use ImageToVTKImageFilter and volume rendering (ray casting). And after segmentation of cutting the images I give below vtkFixedPointVolumeRayCastMapper (SetCroppingRegionPlanes) the Xmin, Xmax, Ymin, Ymax, Zmin and Zmax coordinates, but the result is a black screen. But when I read the images with vtkDICOMImageReader and then segmented with volume rendering, then it works completely well. The problem arises only for watershed -algorithm. Where is my mistake in the code? What should I do?
Thank you.
My Code for Volume Rendering:
int levelForVolumeRendering = (int)this->sliderRangeMin->value()-(int)this->sliderRangeMax->value()/2;
int widhtForVolumeRendering = (int)this->sliderRangeMin->value()+(int)this->sliderRangeMax->value()/2;
mode3D = vtkInteractorStyleTrackballCamera::New();
renderer3D = vtkRenderer::New();
renderWindow3D = vtkRenderWindow::New();
renderWindow3D->AddRenderer(renderer3D);
displayImage3D->SetRenderWindow(renderWindow3D);
displayImage3D->SetInteractorStyle(mode3D);
displayImage3D->Initialize();
vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
oTFun->AddPoint((double)levelForVolumeRendering, 0);
oTFun->AddPoint((double)widhtForVolumeRendering, 1.0);
vtkPiecewiseFunction* gradOpacity = vtkPiecewiseFunction::New();
gradOpacity->AddPoint(0, 0.0);
gradOpacity->AddPoint((int)this->changeLevelInput->value(), 1.0);
gradOpacity->AddPoint((int)this->changeWidthInput->value(), 1.0);
volumeColor = vtkColorTransferFunction::New();
volumeColor->AddRGBPoint((double)levelForVolumeRendering, .62, .36, .18 );
volumeColor->AddRGBPoint((double)widhtForVolumeRendering, .83, .66, 1);
volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetShade(0);
volumeProperty->SetAmbient(0.3);
volumeProperty->SetDiffuse(1.0);
volumeProperty->SetSpecular(0.2);
volumeProperty->SetSpecularPower(50.0);
volumeProperty->SetColor(volumeColor);
volumeProperty->SetScalarOpacity(oTFun);
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationTypeToLinear();
//read with vtkDICOMImageReader and give 6 coordinates for cropping
volumeRayCastMapper = vtkFixedPointVolumeRayCastMapper::New();
volumeRayCastMapper->SetInputConnection(reader2D->GetOutputPort());
volumeRayCastMapper->CroppingOn();
volumeRayCastMapper->SetCroppingRegionPlanes(minpoint4[0], maxpoint4[0], minpoint4[1], maxpoint4[1],minpoint4[2], maxpoint4[2]);
volumeRayCastMapper->SetCroppingRegionFlagsToSubVolume();
volume = vtkVolume::New();
volume->SetProperty(volumeProperty);
volume->SetMapper(volumeRayCastMapper);
camera3D = vtkCamera::New();
camera3D->SetViewUp(0, 0, -1);
camera3D->SetPosition(0, 1, 0);
camera3D->SetFocalPoint(0, 0, 0);
camera3D->ComputeViewPlaneNormal();
camera3D->Azimuth(20);
renderer3D->AddViewProp(volume);
renderer3D->SetActiveCamera(camera3D);
renderer3D->ResetCamera();
camera3D->Dolly(1.3);
renderer3D->ResetCameraClippingRange();
Watershed Segmentation:
typedef float InternalPixelType;
const unsigned int Dimension = 3;
typedef itk::OrientedImage<InternalPixelType, Dimension> ImageType;
typedef itk::ImageSeriesReader<ImageType> ReaderType;
typedef itk::GDCMImageIO ImageIOType;
typedef itk::GDCMSeriesFileNames NamesGeneratorType;
typedef std::vector<std::string> SeriesIdContainer;
typedef std::vector<std::string> FileNamesContainer;
ImageIOType::Pointer dicomIO = ImageIOType::New();
ReaderType::Pointer reader = ReaderType::New();
reader->SetImageIO(dicomIO);
NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
nameGenerator->SetUseSeriesDetails(true);
nameGenerator->AddSeriesRestriction("0008|0021");
nameGenerator->SetDirectory(selectedDirectory);
const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
while( seriesItr != seriesEnd )
{
seriesItr++;
}
std::string seriesIdentifier;
seriesIdentifier = seriesUID.begin()->c_str();
FileNamesContainer fileNames;
fileNames = nameGenerator->GetFileNames(seriesIdentifier);
reader->SetFileNames(fileNames);
reader->Update();
typedef itk::RGBPixel<unsigned char> RGBPixelType;
typedef itk::Image<RGBPixelType,3> RGBImageType;
typedef itk::Image< InternalPixelType, 3 > InternalImageType;
typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<InternalImageType,InternalImageType> GradientMagnitudeFilterType;
GradientMagnitudeFilterType::Pointer gradienMagnitudeFilter = GradientMagnitudeFilterType::New();
gradienMagnitudeFilter->SetInput( reader->GetOutput() );
gradienMagnitudeFilter->SetSigma( 1.0 );
typedef itk::WatershedImageFilter<InternalImageType> WatershedFilterType;
WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();
watershedFilter->SetInput(gradienMagnitudeFilter->GetOutput());
watershedFilter->SetThreshold(this->sliderThresholdWatershed->value());
watershedFilter->SetLevel(this->sliderLevelWatershed->value());
typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType;
typedef WatershedFilterType::OutputImageType LabeledImageType;
connector = ConnectorType::New();
connector->SetInput( watershedFilter->GetOutput());
shiftWatershed = vtkImageShiftScale::New();
shiftWatershed->SetInput(connector->GetOutput());
shiftWatershed->SetOutputScalarTypeToUnsignedChar();
mode3D = vtkInteractorStyleTrackballCamera::New();
renderer3D = vtkRenderer::New();
renderWindow3D = vtkRenderWindow::New();
renderWindow3D->AddRenderer(renderer3D);
displayImage3D->SetRenderWindow(renderWindow3D);
displayImage3D->SetInteractorStyle(mode3D);
displayImage3D->Initialize();
piecewiseWatershed = vtkPiecewiseFunction::New();
piecewiseWatershed->AddPoint(0, 0.0);
piecewiseWatershed->AddPoint(64, 0.0);
piecewiseWatershed->AddPoint(128, 0.5);
piecewiseWatershed->AddPoint(192, 1.0);
piecewiseWatershed->AddPoint(255, 1.0);
volumeColorWatershed = vtkColorTransferFunction::New();
volumeColorWatershed->AddRGBPoint(0, 0.0, 0.0, 0.0);
volumeColorWatershed->AddRGBPoint(64, 1.0, 0.0, 0.0);
volumeColorWatershed->AddRGBPoint(128, 0.0, 0.0, 1.0);
volumeColorWatershed->AddRGBPoint(192, 0.0, 1.0, 0.0);
volumeColorWatershed->AddRGBPoint(255, 0.0, 0.0, 0.0);
volumePropertyWatershed = vtkVolumeProperty::New();
volumePropertyWatershed->SetShade(0);
volumePropertyWatershed->SetAmbient(0.3);
volumePropertyWatershed->SetDiffuse(1.0);
volumePropertyWatershed->SetSpecular(0.2);
volumePropertyWatershed->SetSpecularPower(50.0);
volumePropertyWatershed->SetColor(volumeColorWatershed);
volumePropertyWatershed->SetScalarOpacity(piecewiseWatershed);
volumePropertyWatershed->ShadeOn();
volumePropertyWatershed->SetInterpolationTypeToLinear();
volumeRayCastMapperWatershed = vtkFixedPointVolumeRayCastMapper::New();
volumeRayCastMapperWatershed->SetInputConnection(shiftWatershed->GetOutputPort());
volumeRayCastMapperWatershed->CroppingOn();
volumeRayCastMapperWatershed->SetCroppingRegionPlanes(minpoint4[0], maxpoint4[0], minpoint4[1], maxpoint4[1], minpoint4[2], maxpoint4[2]);
volumeRayCastMapperWatershed->SetCroppingRegionFlagsToSubVolume();
volumeWatershed = vtkVolume::New();
volumeWatershed->SetProperty(volumePropertyWatershed);
volumeWatershed->SetMapper(volumeRayCastMapperWatershed);
camera3D = vtkCamera::New();
camera3D->SetViewUp(0, 0, -1);
camera3D->SetPosition(0, 1, 0);
camera3D->SetFocalPoint(0, 0, 0);
camera3D->ComputeViewPlaneNormal();
camera3D->Azimuth(20);
renderer3D->AddViewProp(volumeWatershed);
renderer3D->SetActiveCamera(camera3D);
renderer3D->ResetCamera();
camera3D->Dolly(1.3);
renderer3D->ResetCameraClippingRange();
__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails.
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100329/4f82e54f/attachment.htm>
More information about the vtkusers
mailing list