[Insight-users] Gradient of Vector Image : ImageAdaptor

Bing Jian bjian at cise . ufl . edu
Thu, 9 Oct 2003 22:24:23 -0400 (EDT)


Hi Luis,

I am still confusing.

Below is what I got from gradient->SetInput(adaptor)
===================================================================
cannot convert parameter 1 from 'class itk::SmartPointer<class
itk::ImageAdaptor<class itk::Image<class itk::Vector<float,3>,3>,class
VectorPixelAccessor> >' to 'const class itk::Image<float,3> *'
===============================================================
In class PixelAccessor I have
    typedef itk::Vector<float,3>   InternalType;
    typedef               float      ExternalType;

In the cxx file, I also have
//typedef float ScalarPixelType;
typedef VectorPixelAccessor::ExternalType ScalarPixelType;
typedef itk::Image<ScalarPixelType, 3> InputScalarImageType;
typedef InputScalarImageType::Pointer InputScalarImagePointer;

typedef itk::Vector<ScalarPixelType, 3> InputVectorPixelType;
typedef itk::Image<InputVectorPixelType, 3> InputVectorImageType;
typedef InputVectorImageType::Pointer InputVectorImagePointer;

typedef itk::CovariantVector<float, 3> GradientVectorPixelType;
typedef itk::Image<GradientVectorPixelType, 3>
GradientVectorImageType;
typedef GradientVectorImageType::Pointer GradientVectorImagePointer;

typedef itk::Matrix<float, 3, 3> JacobianMatrixPixelType;
typedef itk::Image<JacobianMatrixPixelType, 3>
JacobianMatrixImageType;
typedef JacobianMatrixImageType::Pointer JacobianMatrixImagePointer;

The filter is defined as follows:
	typedef
itk::GradientRecursiveGaussianImageFilter<InputScalarImageType,GradientVectorImageType>
GradientFilterType;
	typedef GradientFilterType::Pointer GradientFilterPointer;
	GradientFilterPointer gradient = GradientFilterType::New();

The adaptor is defined as follows:
	typedef itk::ImageAdaptor<  InputVectorImageType,
		VectorPixelAccessor > ImageAdaptorType;
	ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();

So both the input type of gradient filter and externel type of
VectorPixelAccessor are InputScalarImageType (float). and both
the input type of adaptor and internal type of VectorPixelAccessor
are vector<float,3>. But I still got above error.

Thanks a lot.

-- 
Best wishes,
Bing Jian
bjian at cise . ufl . edu


On Thu, 9 Oct 2003, Luis Ibanez wrote:

>
> 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!
> >
>
>
>
>
>