[Insight-users] Erroneous Results calculating the gradient of an image with ITK

Antonio Gómez Barquero agb1 at alu.upct.es
Wed Sep 28 08:12:51 EDT 2011


Sure, as an example, the first 6 results for the first line in each channel:

For MATLAB: 

Channel 1 : 	-3		-4		-1	0		-1
-3
Channel 2 : 	1	0,500000000000000	0	-1
-0,500000000000000	2

For ITK:

Channel 1: 	 1.41		1.41		0          -2.83
-1.417		5.67
Channel 2: 	-4.25		-5.7		-1.42 	0
-1.42		-4.25


-----Mensaje original-----
De: David Doria [mailto:daviddoria at gmail.com] 
Enviado el: miércoles, 28 de septiembre de 2011 14:05
Para: Antonio Gómez Barquero
CC: insight-users at itk.org
Asunto: Re: [Insight-users] Erroneous Results calculating the gradient of an
image with ITK

Thanks,

David



2011/9/28 Antonio Gómez Barquero <agb1 at alu.upct.es>:
> Erroneous Results calculating the gradient of an image with ITK
>
>
>
> 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,InputImageTyp
> e> 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) 
> gradientFilter->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 Gómez Barquero

What do you mean by "completely different"? Is it just different near the
border? Can you post both the ITK and Matlab results for one of the
channels?

David



More information about the Insight-users mailing list