[ITK] Using filters with images of different dimensions (Image broadcast operators?)

Bradley Lowekamp blowekamp at mail.nih.gov
Fri Oct 3 09:41:14 EDT 2014


Hello,


On Oct 3, 2014, at 9:04 AM, Fitze Thomas (fitz) <fitz at zhaw.ch> wrote:

> Hi all
> 
> My current situation: 
> 1. 3D inputImage
> 2. calculate hessian matrix for the image
> 3. calculate trace of hessian matrix for each voxel
> 4. use GetAverageSliceImagefilter to get an average (along 1 dimension) of the hessian trace for each voxel in a slice. This reduces the size of this dimension to 1. I will call this the ‘averageTracePlane’.

Did you consider using a couple MeanProjectionImageFilters[1] to achieve this?


> 
> Now i want to use the averageTracePlane as a sort of lookup table for my inputImage and apply the corresponding averageTrace value. Or in pseudo code: 
> inputImage(x,y,z) = some_constant * averageTracePlane(x,y,1)
> 
> How do i set up a image filter that iterates over my inputImage and cycles through the averageTracePlane? I tried using a BinaryFunctorImageFilter, but could not figure out how to get it to “cycle" trough my averageTracePlane with dimension size 1.
> 

You are not going to be able to use any of the Functor based filters as they will expect the images to be the same dimensions. You will need to create a custom filter to do this. You may find the ImageSliceConstItearatorWithIndex[2] use full in combination with a region iterator. Something like this:



 ImageSliceConstIteratorWithIndex<ImageType> it( image, image->GetRequestedRegion() );
 ImageRegionIteratorType it2(projectedImage, projectedImage->GetRequestedRegion() );

 it.SetFirstDirection(0);
 it.SetSecondDirection(1);

 it.GoToBegin();
 it2.GoToBegin();
 while( !it.IsAtEnd() && !it2.IsAtEnd() )
 {
   while( !it.IsAtEndOfSlice() )
   {
     while( !it.IsAtEndOfLine() )
     {
        value = it.Get() * it2.Get(); 
        ++it;
     }
     it.NextLine();
   }
   it.NextSlice();
  ++it2;
 }


This concept of doing operations on different sized images is common in numerical environments such as Matlab, numpy[3] etc..., we don't currently have it in ITK, and I'm not aware of any Insight Journal Article which contributes it either. I think this could be quite a useful filter, say BroadcastingBinaryFunctorImageFilter.

Brad




> Thanks a lot,
> Thomas

[1] http://www.itk.org/Doxygen/html/classitk_1_1MeanProjectionImageFilter.html
[2] http://www.itk.org/Doxygen/html/classitk_1_1ImageSliceConstIteratorWithIndex.html
[3] http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community




More information about the Community mailing list