[Insight-users] Erroneous Results calculating the gradient of an image with ITK
David Doria
daviddoria at gmail.com
Wed Sep 28 08:04:40 EDT 2011
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,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 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