2011-09-22 74 views
1

我想計算一個二維圖像的梯度的x和y分量。如在MATLAB中用[dT2,dT1] =梯度(T)計算;itk一個圖像的梯度的x和y分量

ReaderType::Pointer T_g  // image 
FilterType::Pointer gradientFilter = FilterType::New(); 
gradientFilter->SetInput(T_g->GetOutput()); 
gradientFilter->Update(); 

有了這句話,我得到的結果,但我想有x分量和y分量 gradientFilter-> GetOutput() 是否有任何的方法來提取呢?我正在尋找它,但我沒有積極的結果!

非常感謝

安東尼奧

回答

1

的gradientFilter的輸出將是一個矢量圖像。我從你的描述中假設它是 2d圖像!

ImageType::IndexType index; 
index[0]=xcoord; 
index[1]=ycoord; 

gradientFilter->GetOutput()->GetPixel(index)[0]; // will return first component of xcoord,ycoord 
+0

最後 '[0]' 不工作,另外,如果我嘗試指標[2] = 0算法中給我的錯誤! – Antonio

+0

如果您使用2d圖像,index [2]應該會出錯!嘗試「std :: cout << gradientFilter-> GetOutput() - > GetPixel(index)<< std :: endl」,看看輸出是什麼 – dirkboye

1

http://www.vtk.org/Wiki/ITK/Examples

http://www.vtk.org/Wiki/ITK/Examples/ImageProcessing/NthElementImageAdaptor

模板 類ITK :: NthElementImageAdaptor <的TImage,TOutputPixelType>

呈現圖像爲被構成其的像素的第N個元素的。

它假定像素是容器類型,並且在它們的API中定義了一個運算符[](unsigned int)。

根據C++默認投射規則的輸入和輸出圖像類型執行附加投射。

維基例子:

All Examples 

Extract a component of an itkImage with pixels with multiple components 

Process the nth component/element of a vector image