2011-09-28 111 views
1

在頭文件中,我聲明瞭所有這些類型,「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」之前看到奇怪的東西?或者在計算漸變的過程中?

非常感謝!

安東尼奧

回答

2

ITK應該尊重體素間距的計算。你的圖像是否具有各向同性的單位間距?

這可能會解釋與matlab的區別。

+0

是做了,你是對的,解決方案是添加以下行:\t gradientFilter-> SetUseImageSpacingOff(); //用於在各向同性像素空間中推導 – Antonio

1

的問題是在圖像的間隔,剛剛加入這一行:

gradientFilter->SetUseImageSpacingOff(); // for derivation in isotropic pixel space 

問題解決了,並推導在各向同性空間

+0

注意:這就是爲什麼使用matlab進行真實世界的醫學成像可能非常危險。由於實際原因,大多數圖像捕捉都是等時的。在體素空間計算可產生微妙的差異,這可能會影響解釋並最終影響患者安全。 – Hans