[Insight-users] Gradient of Vector Image : ImageAdaptor

Luis Ibanez luis . ibanez at kitware . com
Thu, 09 Oct 2003 21:50:29 -0400


Hi Bing,

ImageAdaptors have the same API as itkImages.
You are allowed to use the smart pointer to the
image adaptor in any place where a pointer to
the image is expected.

However, for this to work, the image adaptor type
*must* correspond exactly to the image type.

One easy way to enforce this is to use the
types from the PixelAccessor when defining the
type of the InputScalarType for the Gradient
filter.

For example:

typedef VectorPixelAccessor::ExternalType   InputScalarPixelType;
typedef itk::Image< InputScalarPixelType, dimension >
                                             InputScalarImageType;

typedef itk::GradientGaussianRecursiveImageFilter<
                                      InputScalarImageType,
                                      VectorImageType >
                                            GradientFilterType;

GradientFilterType::Pointer gradient = GradientFilterType::New();
AdaptorType::Pointer        adaptor  = AdaptorType::New();

gradient->SetInput( adaptor );


---

A WARNING about your current code: You are making a loop for
processing all the components of the input image vector and
get the gradient of each one. That's fine, except for the
last line were you take the output of the gradient filter and
"put it" in an array.

What will happen is that all the pointers in "gradient_out[i]"
will end up pointing to the same image, which is the single
output of the gradient filter.

You must actually transfer the pixel data to another image.


Regards,


   Luis



------------------
Bing Jian wrote:
>>Hi Jian,
>>
>>It will not be easy, but it will be fun  :-)
>>
>>
>>1) Create an ImageAdaptor that will
>>    extract the components of the Offset
>>    and present it as a scalar image.
>>
>>    follow the example in the SoftwareGuide
>>    http://www . itk . org/ItkSoftwareGuide . pdf
>>    Section 12.3, pdf-page 526, paper-page 500.
>>
>>2) Instantiate three of these ImageAdaptors and
>>    set them to extract the components {0,1,2}
>>    of the Offset respectively.
>>
>>3) Instantiate three GradientRecursiveImageFilters
>>    and connect each one to one of the ImageAdaptors.
> 
> 
>   To do this, I wrote following code snippet:
> ================================================================================
>   unsigned int i,j, vector_dimension = 3, image_dimension = 3;
> 
>   typedef itk::GradientRecursiveGaussianImageFilter<InputScalarImageType,GradientVectorImageType>
> GradientFilterType;
>   typedef GradientFilterType::Pointer GradientFilterPointer;
>   GradientVectorImageType::Pointer gradient_out[vector_dimension];
> 
>   typedef itk::ImageAdaptor<  InputVectorImageType,
> 		VectorPixelAccessor > ImageAdaptorType;
>   ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
> 
>   VectorPixelAccessor accessor;
>   GradientFilterPointer gradient = GradientFilterType::New();
> 
>    for (i=0;i<vector_dimension;i++){
> 			  accessor.SetIndex(i);
> 			  adaptor->SetPixelAccessor(accessor);
> 			  adaptor->SetImage(input);
> 
> 			  gradient->SetInput(adaptor);
> 
> 			  gradient->Update();
> 			  gradient_out[i] = gradient->GetOutput();
>   }
> ================================================================================
>   I am getting error at this line:
>      gradient->SetInput(adaptor);
>   The example is using Rescaler->SetInput(adaptor), but seems
> gradientfilter is expecting a pointer to image instead of adaptor.
> and there is no method like adaptor->GetOutput().
> 
> So what should I do to pass the extracted scalar image to filter?
> 
> Thanks in advance!
>