在頭文件中,我聲明瞭所有這些類型,「Gradient ImageFilter」用於計算2D圖像的梯度,「VectorIndexSelectionCastImageFilter」用於選擇「由於計算梯度的結果是矢量圖像,所以梯度計算的「x」和「y」分量。用ITK計算圖像梯度的錯誤結果
typedef double operatorValueType;
typedef double outputValueType;
typedef double InputPixelType;
typedef itk::Image<InputPixelType, 2> InputImageType;
typedef itk::GradientImageFilter< InputImageType, operatorValueType, outputValueType> GradientFilterType;
//for extracting a scalar from the vector image
typedef double OutputPixelTypeImage;
typedef double ComponentType;
typedef itk::CovariantVector<ComponentType,2> OutputPixelType;
typedef itk::Image <OutputPixelType, 2> OutputImageType;
typedef itk::VectorIndexSelectionCastImageFilter<OutputImageType,InputImageType> SelectionFilterType; // < intputType , outputType>
的聲明後,該代碼感興趣的主要部分是如下:
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetInput(T_g->GetOutput()); // From T_g (is a reader) comes the image
gradientFilter->Update();
SelectionFilterType::Pointer componentExtractor_x = SelectionFilterType::New();
SelectionFilterType::Pointer componentExtractor_y = SelectionFilterType::New();
componentExtractor_x->SetIndex(0);// x component of the gradient
componentExtractor_y->SetIndex(1);// y component of the gradient
componentExtractor_x->SetInput(gradientFilter->GetOutput());
componentExtractor_y->SetInput(gradientFilter->GetOutput());
componentExtractor_x->Update();
componentExtractor_y->Update();
看來,一切工作正常,但問題是,當我讀到的形象和我進行比較用Matlab中的漸變計算(我認爲是正確的),結果是完全不同的......任何人都在使用「VectorIndexSelectionCastImageFilter」之前看到奇怪的東西?或者在計算漸變的過程中?
非常感謝!
安東尼奧
是做了,你是對的,解決方案是添加以下行:\t gradientFilter-> SetUseImageSpacingOff(); //用於在各向同性像素空間中推導 – Antonio