[vtkusers] How to use vtkImageGradient?
wang minyou
wmy1024 at hotmail.com
Thu Apr 29 10:30:39 EDT 2004
Hello everyone,
I have some problem to use vtkImageGradient. According to the example in
vtk-doc, I use vtkImageGradient to do image processing. But in runtime
occurs some errors in vtkOutputWindow, which says:vtkImageGradient
(019200A0): Execute: input has more than one components. The input to
gradient should be a single component image. Think about it. If you insist
on using a color image then run it though RGBToHSV then ExtractComponents
to get the V components. That's probably what you want anyhow.
But I want to do the Gradient of the grey level of the image.How can I do
that?
Thank you very much!
some codes are as follow:
vtkImageGaussianSmooth* pGaussianSmooth=vtkImageGaussianSmooth::New();
pGaussianSmooth->SetInput(bmpReader->GetOutput());
pGaussianSmooth->SetStandardDeviation(1.0);
pGaussianSmooth->SetDimensionality(2);
pGaussianSmooth->SetRadiusFactors(10,10,0);
vtkImageGradient* imgGradient=vtkImageGradient::New();
imgGradient->SetInput(pGaussianSmooth->GetOutput());
imgGradient->SetDimensionality(2);
vtkImageMagnitude* imgMagnitude=vtkImageMagnitude::New();
imgMagnitude->SetInput(imgGradient->GetOutput());
// non maximum suppression
vtkImageNonMaximumSuppression* nonMax=vtkImageNonMaximumSuppression::New();
nonMax->SetVectorInput(imgGradient->GetOutput());
nonMax->SetMagnitudeInput(imgMagnitude->GetOutput());
nonMax->SetDimensionality(2);
vtkImageConstantPad* pad=vtkImageConstantPad::New();
pad->SetInput(imgGradient->GetOutput());
pad->SetOutputNumberOfScalarComponents(3);
pad->SetConstant(0);
vtkImageToStructuredPoints* i2sp1=vtkImageToStructuredPoints::New();
i2sp1->SetInput(nonMax->GetOutput());
i2sp1->SetVectorInput(pad->GetOutput());
// link edgles
vtkLinkEdgels* imgLink=vtkLinkEdgels::New();
imgLink->SetInput((vtkImageData*)i2sp1->GetOutput());
imgLink->SetGradientThreshold(2);
//threshold links
vtkThreshold* thresholdEdgels=vtkThreshold::New();
thresholdEdgels->SetInput((vtkDataSet*)imgLink->GetOutput());
thresholdEdgels->ThresholdByUpper(10);
thresholdEdgels->AllScalarsOff();
vtkGeometryFilter* gf=vtkGeometryFilter::New();
gf->SetInput((vtkDataSet*)thresholdEdgels->GetOutput());
vtkImageToStructuredPoints* i2sp=vtkImageToStructuredPoints::New();
i2sp->SetInput(imgMagnitude->GetOutput());
i2sp->SetVectorInput(pad->GetOutput());
//subpixel them
vtkSubPixelPositionEdgels* spe=vtkSubPixelPositionEdgels::New();
spe->SetInput(gf->GetOutput());
spe->SetGradMaps(i2sp->GetOutput());
vtkStripper* strip=vtkStripper::New();
strip->SetInput(spe->GetOutput());
vtkPolyDataMapper* dsm=vtkPolyDataMapper::New();
dsm->SetInput(strip->GetOutput());
dsm->ScalarVisibilityOff();
pRenWin->AddRenderer(pRender2);
pRender2->SetViewport( 0.5 , 0.0 , 1.0 , 1.0 );
pRender2->SetBackground( 1.0 , 1.0 , 1.0 );
vtkActor * myActor = vtkActor::New();
myActor->SetMapper(dsm);
pRender2->AddActor(myActor);
_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: http://messenger.msn.com/cn
More information about the vtkusers
mailing list