使用高斯核进行一维卷积

发布于 2024-12-16 11:18:38 字数 1480 浏览 1 评论 0原文

我的目标是计算 2D 图像的每一行(在 x 方向) 按照 Cory 的提示后,我尝试使用“ConvolutionImageFilter”,并使用我之前计算的高斯值制作内核。 我查看了这个示例(http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ConvolutionImageFilter),我的问题是如何将高斯滤波器的值包含到内核中,我尝试使用代码下面它编译了,但当我更新卷积过滤器时,执行似乎没有结束……因此,我认为我做错了什么。我的代码在下面,并不是那么多,如果有人可以提供一些帮助,我将非常感激!!!!

typedef itk::ConvolutionImageFilter <ImageType> ConvFilterType;

ImageType::Pointer kernel = ImageType::New();
CreateKernel(kernel, Gaussian , 256);

//Convolve image with kernel
ConvFilterType::Pointer convolutionFilter = ConvFilterType::New();
convolutionFilter->SetInput(Li_itk);
convolutionFilter->SetImageKernelInput(kernel);
convolutionFilter->Update();

void Reg_image_v2::CreateKernel(Reg_image_v2::ImageType::Pointer kernel, double *Gaussian, unsigned int width) {

ImageType::IndexType start;
start.Fill(0);

ImageType::SizeType size;
    size[0] = width;
size[1] = 1;

ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);

kernel->SetRegions(region);
kernel->Allocate();

ImageType::IndexType pixelIndex;
for (int i = 0 ; i < width ; i ++){
    pixelIndex[0] = i ;
    pixelIndex[1] = 0 ;
    kernel->SetPixel(pixelIndex,Gaussian[i]);
}

itk::ImageRegionIterator<ImageType> imageIterator(kernel, region);

while(!imageIterator.IsAtEnd()) 

{
//imageIterator.Set??

++imageIterator; //operator++  increments the iterator one position in the positive direction
}


} // end createKernel

安东尼奥

My goal is to calculate the calculation in each row of a 2D-image ( in the x-direction)
After following the tip from Cory I am trying to use the ‘ConvolutionImageFilter’, and make a kernel with the Gaussian values I calculate before.
I took a look to this example (http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ConvolutionImageFilter) and my question is how to include the values of the Gaussian filter to the kernel, I tried wit the code below and it compiles, but it seems the execution has no end when I update the convolutionFilter… Because of that I think that I am doing something wrong. My code is below and is not so much, if some can give some help I would appreciate that really a lot !!!!.

typedef itk::ConvolutionImageFilter <ImageType> ConvFilterType;

ImageType::Pointer kernel = ImageType::New();
CreateKernel(kernel, Gaussian , 256);

//Convolve image with kernel
ConvFilterType::Pointer convolutionFilter = ConvFilterType::New();
convolutionFilter->SetInput(Li_itk);
convolutionFilter->SetImageKernelInput(kernel);
convolutionFilter->Update();

void Reg_image_v2::CreateKernel(Reg_image_v2::ImageType::Pointer kernel, double *Gaussian, unsigned int width) {

ImageType::IndexType start;
start.Fill(0);

ImageType::SizeType size;
    size[0] = width;
size[1] = 1;

ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);

kernel->SetRegions(region);
kernel->Allocate();

ImageType::IndexType pixelIndex;
for (int i = 0 ; i < width ; i ++){
    pixelIndex[0] = i ;
    pixelIndex[1] = 0 ;
    kernel->SetPixel(pixelIndex,Gaussian[i]);
}

itk::ImageRegionIterator<ImageType> imageIterator(kernel, region);

while(!imageIterator.IsAtEnd()) 

{
//imageIterator.Set??

++imageIterator; //operator++  increments the iterator one position in the positive direction
}


} // end createKernel

Antonio

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

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

发布评论

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

评论(1

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