使用 ITK 计算图像梯度的错误结果

发布于 2024-12-07 03:18:24 字数 1771 浏览 1 评论 0原文

在头文件中,我声明了所有这些类型,“Gradient ImageFilter”用于计算 2D 图像的梯度,“VectorIndexSelectionCastImageFilter”用于选择梯度计算的“x”和“y”分量,因为事实上,计算梯度的结果是矢量图像。

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”之前使用过并看到一些奇怪的东西吗?或者在计算梯度的过程中?

非常感谢!

安东尼奥

In the header file, I declare all of this types, The “Gradient ImageFilter” is for calculate the gradient of a 2D image, and the “VectorIndexSelectionCastImageFilter” is for selecting the ’x’ and ‘y’ component of the gradient calculating, due to the fact that the result of computing th gradient is a vector image.

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>

After the declarations, the main part of interest of the code is below:

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();

It seems that everything works fine, but the problem is that when I read the image and I compare it with the calculation of the gradient in Matlab (which I assume to be correct) the results are completely different…Anyone has used before the “VectorIndexSelectionCastImageFilter” and see something strange? Or in the process of calculating the gradient?

Thanks so much!

Antonio

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

靑春怀旧 2024-12-14 03:18:24

ITK 在计算中应考虑体素间距。您的图像具有各向同性单位间距吗?

这可以解释与 matlab 的差异。

ITK should respect voxel spacing in the computations. Do you images have isotropic unit spacing?

This could account for the differences with matlab.

且行且努力 2024-12-14 03:18:24

问题出在图像的间距上,只需添加这一行:

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

问题就解决了,并且在各向同性空间中进行了推导

The problem was in the spacing of the image, just by adding this line:

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

the problem was solved, and the derivation was done in an isotropic space

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文