[Rtk-users] for information

Cyril Mory cyril.mory at creatis.insa-lyon.fr
Fri Jun 12 10:02:03 EDT 2015


Hi Lin,

Let us continue this conversation on the RTK mailing list.
ITK has a mechanism to do what you need, it is called ImageAdaptors, and 
in your case, NthElementImageAdaptor.

The example in the ITK documentation is very clear:
http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/ProcessingNthImageElement

This is if you want to send your component images to various filters 
after having extracted them from the original gradient image. If, on the 
other hand, you only need to perform some simple processing, you can 
elaborate on the code I sent, for example:

itk::ImageRegionIterator<TGradientOutputImageType> gradientIterator
(yourSecondGradientImage,
yourSecondGradientImage->GetLargestPossibleRegion());
itk::ImageRegionIterator<TGradientOutputImageType> outputIterator
(yourOutputGradientImage,
yourOutputGradientImage->GetLargestPossibleRegion());

typename  TGradientOutputImageType::PixelType vector;
while(!gradientIterator.IsAtEnd())
{
     vector = gradientIterator.Get();
     vector[0] += 1: // Or whatever other processing you want to perform 
on the first coordinate
     vector[1] += 1: // Or whatever other processing you want to perform 
on the second coordinate
     vector[2] += 1: // Or whatever other processing you want to perform 
on the third coordinate
     outputIterator.Set( vector );
     ++gradientIterator;
     ++outputIterator;
}

Regarding the Fourier transform:
ITK has built-in FFT (slow) and can use FFTW (you have to activate it in 
the CMake options, as it has a different licensing than ITK). I has been 
a while since I last used it, so I cannot help much. I recommend you 
have a look at the documentation, and maybe write to the ITK mailing 
list if you still do not succeed. A good place to start could be here : 
http://www.itk.org/Doxygen/html/group__ITKFFT.html

Regards,
Cyril

On 06/12/2015 03:32 PM, liwang wrote:
> Dear Cyril,
>
>
> Good afternoon! Thanks very much for your reply!
>
> In fact, I only have an rtk::ForwardDifferenceGradientImageFilter
>
> and the output "u" of this filter is three gradient images (u_1, u_2, 
> u_3)  for three directions (x ,y, z) of the input image
>
> Now I want to do some things to these gradient images separately.
>
> And my problem is: I don't know to get these gradient images for 
> directions (x,y,z) from the output  "u" the 
> "ForwardDifferenceGradientImageFilter".
>
>
> Thanks very much!
> PS: How can I implement inverse FFT algorithm on RTK?
>
> lin
>
>
>
>
>
> On 2015-06-12 09:37, Cyril Mory wrote:
>> Hi Lin,
>>
>> Let me re-explain what I understand. And correct me if I'm wrong.
>> You want to compute the subtraction of two gradient images: one is the
>> output of an rtk::ForwardDifferenceGradientImageFilter, and you did
>> not explain where the other one comes from.
>>
>> One first important thing to understand: ITK can compute the
>> subtraction of two covariant vectors u and v easily. You just have to
>> write "w = u - v", and internally it will compute
>> (w_1) = (u_1 - v_1)
>> (w_2) = (u_2 - v_2)
>> (w_3) = (u_3 - v_3)
>> because the operator '-' between two covariant vectors is properly
>> redefined in ITK.
>>
>> Therefore, a simple subtract filter can do what you want if you set
>> the type correctly (TGradientOutputImageType).
>> If you want to do it with iterators, you do not need the loop "for
>> (unsigned int h=0; h < 3; h++)"
>> Simply writing something like this should work :
>>
>> ----------------
>> itk::ImageRegionIterator<TGradientOutputImageType> gradientIterator1
>> (m_Gradient->GetOutput(),
>> m_Gradient->GetOutput()->GetLargestPossibleRegion());
>> itk::ImageRegionIterator<TGradientOutputImageType> gradientIterator2
>> (yourSecondGradientImage,
>> yourSecondGradientImage->GetLargestPossibleRegion());
>> itk::ImageRegionIterator<TGradientOutputImageType> outputIterator
>> (yourOutputGradientImage,
>> yourOutputGradientImage->GetLargestPossibleRegion());
>>
>> while(!gradientIterator.IsAtEnd())
>> {
>>     outputIterator.Set( gradientIterator1.Get() - 
>> gradientIterator2.Get() );
>>     ++gradientIterator1;
>>     ++gradientIterator2;
>>     ++outputIterator;
>> }
>> ----------------
>>
>> Does that help ?
>> Cyril
>>
>> On 06/11/2015 07:26 PM, liwang wrote:
>>> Dear Cyril,
>>>
>>>     Good afternoon! I hope everything goes well for you
>>>
>>>     I am writing for consulting some information about 
>>> itk::covariantVector, and  I want subtract each gradient from the 
>>> "TGradientOutputImageType" type.
>>>
>>>     If I have a image f, and after gradient filter, gradient of f 
>>> was obtained, and the definition of of Gradient image is:
>>>
>>> typedef float OutputPixelType;
>>> const unsigned int Dimension = 3;
>>> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>>> typedef itk::Image <itk::CovariantVector 
>>> <OutputPixelType,Dimension>, Dimension> TGradientOutputImageType;
>>>
>>>
>>> Now My problem is I want obtain gradient_x, gradient_y, gradient_z 
>>> from the output of the rtk::ForwardDifferenceGradientImagefilter 
>>> (filter to compute gradient of f)
>>>
>>> I mean, I tried many methods to subtract gradients of each direction 
>>> from the output of gradient filter, but I failed.
>>>
>>>
>>> I tried :
>>> ====>
>>> itk::ImageRegionIterator<TGradientOutputImageType> gradientIterator1 
>>> (m_Gradient->GetOutput(), 
>>> m_Gradient->GetOutput()->GetLargestPossibleRegion());
>>> itk::Image<float,3>::IndexType imageIndex;
>>>     for (unsigned int h=0; h < 3; h++)
>>>     {
>>>                 pixelIndex[0]=h;
>>>                 itk::CovariantVector<float,3> v = 
>>> gradientIterator1.GetImage()->GetPixel(imageIndex);
>>>
>>>     }
>>> ===>
>>> OutputImageType::RegionType region= 
>>> m_Gradient->GetOutput()->GetLargestPossibleRegion();
>>> OutputImageType::pointer gradient_x;
>>>
>>> gradient_x->SetRegions(region);
>>>
>>>
>>>
>>> Would you like to give me some advice?
>>> Thanks very much!
>>>
>>> Best wishes!
>>>
>>> Lin
>>> 2015-6-11
>




More information about the Rtk-users mailing list