[Insight-users] 1D Convolution with Gaussian Kernel using
Nicholas Tustison
ntustison at gmail.com
Fri Nov 18 12:29:08 EST 2011
Did you look at the example?
http://www.vtk.org/Wiki/ITK/Examples/Operators/GaussianOperator
On Nov 18, 2011, at 7:17 AM, Antonio Gómez Barquero wrote:
>
>
> Hi Nicholas,
>
> Thanks so much for your answer, is helping me quite a lot.
>
> Still have some difficulties... I use the NeighborhoodOperatorImageFilter,
> it compiles quite fast, but the output is wrong. I only have results on the
> first row, and they have just the opposite behavior that the one I was
> expecting ( i mean, I expected then numbers go decreasing to zero with
> x-increasing but they just increase until reaching the value '1' .
>
> Just one question about the 'setVariance' that is not documented in the help
> of the class... is it in terms of 'mm' or pixels? If it's not in terms of
> pixels...what should I do for having it in that way?
>
> Thanks so much again!!!
>
> Antonio
>
> -----Mensaje original-----
> De: Nicholas Tustison [mailto:ntustison at gmail.com]
> Enviado el: jueves, 17 de noviembre de 2011 18:50
> Para: Antonio Gómez Barquero
> CC: 'Cory Quammen'; insight-users at itk.org
> Asunto: Re: [Insight-users] 1D Convolution with Gaussian Kernel using
>
> Hi Antonio,
>
> Instead of using the ConvolutionImageFilter, you might want to explore
> existing functionality in combining the GaussianOperator with the
> NeighborhoodOperatorImageFilter.
>
> typedef itk::NeighborhoodOperatorImageFilter<ImageType, ImageType>
> SmootherType;
> typename SmootherType::Pointer smoother = SmootherType::New();
>
> typedef GaussianOperator<PixelType, ImageDimension> GaussianType;
> GaussianType gaussian;
> gaussian.SetVariance( variance );
> gaussian.SetDirection( 0 );
>
> gaussian.SetMaximumError( 0.001 );
> gaussian.SetMaximumKernelWidth(
> inputImage->GetRequestedRegion().GetSize()[0] );
> gaussian.CreateDirectional();
>
> smoother->SetOperator( gaussian );
> smoother->SetInput( inputImage );
> smoother->Update();
>
> smoothImage = smoother->GetOutput();
>
> However, in case you want to keep your image, you can use
> GaussianImageSource to create 2-D image which has size Nx1 and then that
> image should plug right into the ConvolutionImageFilter. I just did it
> right now with my code and it seemed to work as expected.
>
> Nick
>
>
>
> On Nov 17, 2011, at 4:42 AM, Antonio Gómez Barquero wrote:
>
>>
>>
>> Hi!
>>
>> You were right, now it compiles, but I only have some numbers in the
>> first
>> 20 positions, after that everything is 0, so is wrong, also it takes
>> around
>> 15 seconds to perform the calculation which is a crazy thing!.
>>
>> I prefer to generate the Gaussian myself and after that translate it
>> into an image ( kernel in this case) because I am doing work also with
>> Matlab, and I would like to use the same Gaussian.
>>
>> But I think I am missing something in the body of the iteration ,
>> something that performs the convolution itself or maybe the point of
>> doing the convolution in x-axis in 1D....
>>
>> while(!imageIterator.IsAtEnd())
>> {
>> //imageIterator.Set??
>>
>> ++imageIterator; //operator++ increments the iterator one position
>> in the positive direction
>>
>> }
>>
>>
>> Also, the perfect final would be to have a Kernel of 25 pixels ( the
>> same I have originally in my Matlab program), and then performing the
>> convolution in each row of the x-direction of the image...I think that
>> must be a way...so I follow reading the ITK manual and let's see I found
> something.
>>
>> Any Tip or idea or help will be highly appreciated!
>>
>> Antonio
>>
>> -----Mensaje original-----
>> De: Cory Quammen [mailto:cquammen at cs.unc.edu] Enviado el: miércoles,
>> 16 de noviembre de 2011 17:28
>> Para: Antonio Gómez Barquero
>> CC: insight-users at itk.org
>> Asunto: Re: [Insight-users] 1D Convolution with Gaussian Kernel using
>>
>> Antonio,
>>
>> It looks like you are defining your kernel to be 256x256, not 256x1.
>> You probably want to call
>>
>> size[0] = width;
>> size[1] = 1;
>>
>> instead of
>>
>> size.Fill(width);
>>
>> You might want to consider using the GaussianImageSource
>> (http://www.itk.org/Doxygen/html/classitk_1_1GaussianImageSource.html)
>> to generate your Gaussian.
>>
>> Hope that helps,
>> Cory
>>
>> 2011/11/16 Antonio Gómez Barquero <agb1 at alu.upct.es>:
>>> SORRY, the last e-mail was icomplete, here is ok:
>>>
>>>
>>>
>>> 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/ConvolutionImag
>>> e
>>> Filter) 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.Fill(width);
>>>
>>> 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 Gómez Barquero
>>>
>>>
>>>
>>> Ingeniero de Telecomunicaciones -Becario Investigador asociado a
>>> Actividades de I+D+I
>>>
>>> GTTS ( Grupo de Tratamiento y Teoría de la Señal)[
>>> http://gtts.upct.es/]
>>>
>>> UPCT (Universidad Politécnica de Cartagena)[ http://www.upct.es/]
>>>
>>>
>>>
>>> _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.html
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>>
>>
>>
>> --
>> Cory Quammen
>> Research Associate
>> Department of Computer Science
>> The University of North Carolina at Chapel Hill
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>
>
More information about the Insight-users
mailing list