[Insight-users] How to create a set of spatially distributed images

Julien Jomier julien.jomier at kitware.com
Tue Jan 9 12:11:28 EST 2007


Ali,

I just put a fix in ITK cvs for the loop issue.

Note that you can set the scale of the gaussian using:
   gaussianObject->GetIndexToObjectTransform()->SetScale(2.0);

I'll try to implement the new filter today or tomorrow.

Hope that helps,

Julien

Ali - wrote:
> Julien,
>  
> It seems I pasted the wrong code, what I wanted to describe was that,
> even with having GaussianType::New() inside the loop, the final image
> shows only 1 gaussian object. So the code should be like:
>  
> typedef itk::GaussianSpatialObject< 2 > GaussianType;
> typedef itk::GroupSpatialObject< 2 > GroupSpatialObjectType;
> GroupSpatialObjectType::Pointer group = GroupSpatialObjectType::New();
> for(unsigned int i = 0; i < 10; i++)
> {
>   GaussianType::Pointer gaussianObject = GaussianType::New();
>   gaussianObject->GetObjectToParentTransform()->SetOffset(i * 30);
>   gaussianObject->ComputeObjectToWorldTransform();
>  
>    group->AddSpatialObject(gaussianObject);
>  }
>  
> I even tried this with a vector of GroupSpatialObjectType::Pointer ending up
> with the same result of only 1 gaussian object. Am I missing a call to a 
> method
> or something?
>  
> Do you think if the new filter itkSpatialGaussianObjectToImageFilter 
> could be
> ready for this week or would it take a long time to develop it? Would it 
> be available
> from the CVS? I could give it a try if there is a similar filter to 
> begin with.
>  
>  
>  > Ali,
>  >
>  > You need to put the GaussianType::New() inside the loop so that a new
>  > GaussianObject is created and added to the group at every iteration.
>  >
>  > The itkSpatialObjectToImageFilter is meant to be very generic and
>  > therefore might be slow for this kind of computation. We might want to
>  > create a new filter specific to the GaussianSpatialObject. If you want
>  > to give it a try, go for it, otherwise let me know (I might be able to
>  > work on it only after tomorrow though).
>  >
>  > Julien
>  >
>  > Ali - wrote:
>  > > Julien,.
>  > >
>  > > Thanks, that does the job! However, if we want to add more than one
>  > > gaussian object by
>  > > adding them to a group, the group only points to one instance of a
>  > > gaussian object:
>  > >
>  > > typedef itk::GaussianSpatialObject< 2 > GaussianType;
>  > > typedef itk::GroupSpatialObject< 2 > GroupSpatialObjectType;
>  > > GroupSpatialObjectType::Pointer group = GroupSpatialObjectType::New();
>  > > for(unsigned int i = 0; i < 10; i++)
>  > > {
>  > > gaussianObject->GetObjectToParentTransform()->SetOffset(i * 30);
>  > > gaussianObject->ComputeObjectToWorldTransform();
>  > >
>  > > group->AddSpatialObject(gaussianObject);
>  > > }
>  > >
>  > > The above code can generate only 1 gaussian object. How is it possible
>  > > to add a new
>  > > one to the group where each of them have different properties? By the
>  > > way, the use of
>  > > this algorithms seems to be sort of slow, it takes about a second 
> or two
>  > > per gaussian
>  > > object for a 512 x 512 image -- is it normal?
>  > >
>  > >
>  > >
>  > > > Ali,
>  > > >
>  > > > If you are creating a 2D image, you have to make the dimension of the
>  > > > GaussianSpatialObject of dimension 2:
>  > > >
>  > > > typedef itk::GaussianSpatialObject< 2 > GaussianType;
>  > > >
>  > > > This should solve your problem with the corrupted size.
>  > > >
>  > > > Also, if you want to put your gaussian at a specific location (in 
> world
>  > > > coordinate). Let's say at (100,100)mm. You can do something like:
>  > > >
>  > > > 
> gaussianObject->GetObjectToParentTransform()->SetOffsetComponent(100);
>  > > > gaussianObject->ComputeObjectToWorldTransform();
>  > > >
>  > > > Hope that helps,
>  > > >
>  > > > Julien
>  > > >
>  > > > Ali - wrote:
>  > > > > Gaetan,
>  > > > >
>  > > > > I have tried SpatialObjectToImageFilter as explained in the ITK
>  > > software guide ending up with this error:
>  > > > >
>  > > > > stack around the variable 'size' was corrupted.
>  > > > >
>  > > > > I use visual studio 8 under xp. I have already set the size for 
> the
>  > > filter. Here is the code (you can get rid of the VTK part if you dont
>  > > want to see the result):
>  > > > >
>  > > > > ----------------------------------------------------------
>  > > > >
>  > > > > #if defined(_MSC_VER)
>  > > > > #pragma warning ( disable : 4786 )
>  > > > > #endif
>  > > > >
>  > > > > #include "itkImage.h"
>  > > > > #include "itkGaussianSpatialObject.h"
>  > > > > #include "itkGroupSpatialObject.h"
>  > > > > #include "itkSpatialObjectToImageFilter.h"
>  > > > >
>  > > > > #include "itkImageToVTKImageFilter.h"
>  > > > > #include "vtkImageViewer.h"
>  > > > > #include "vtkRenderWindowInteractor.h"
>  > > > >
>  > > > > int main(int, char *[])
>  > > > > {
>  > > > > const unsigned int ParticleImageCount = 1;
>  > > > >
>  > > > > typedef unsigned char PixelType;
>  > > > > const unsigned int Dimension = 2;
>  > > > >
>  > > > > typedef itk::Image< PixelType, Dimension > ImageType;
>  > > > > typedef itk::GaussianSpatialObject< 3 > GaussianType;
>  > > > > typedef itk::SpatialObjectToImageFilter< GaussianType, ImageType >
>  > > SpatialObjectToImageFilterType;
>  > > > >
>  > > > > GaussianType::Pointer gaussianObject = GaussianType::New();
>  > > > > gaussianObject->SetMaximum(2);
>  > > > > gaussianObject->SetRadius(5);
>  > > > >
>  > > > > ImageType::SizeType size;
>  > > > > size[0] = 200;
>  > > > > size[1] = 200;
>  > > > > SpatialObjectToImageFilterType::Pointer imageFilter =
>  > > SpatialObjectToImageFilterType::New();
>  > > > > imageFilter->SetSize(size);
>  > > > >
>  > > > > imageFilter->SetInput(gaussianObject);
>  > > > > imageFilter->Update();
>  > > > >
>  > > > > ImageType::Pointer pImage = imageFilter->GetOutput();
>  > > > >
>  > > > > typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
>  > > > > ConnectorType::Pointer connector = ConnectorType::New();
>  > > > > connector->SetInput( pImage );
>  > > > > vtkImageViewer* viewer = vtkImageViewer::New();
>  > > > > vtkRenderWindowInteractor* renderWindowInteractor =
>  > > vtkRenderWindowInteractor::New();
>  > > > > viewer->SetupInteractor( renderWindowInteractor);
>  > > > > viewer->SetInput( connector->GetOutput() );
>  > > > > viewer->Render();
>  > > > > viewer->SetColorWindow( 255);
>  > > > > viewer->SetColorLevel( 128);
>  > > > > renderWindowInteractor->Start();
>  > > > >
>  > > > > return 0;
>  > > > > }
>  > > > >
>  > > > >
>  > > > > _________________________________________________________________
>  > > > > Be one of the first to try Windows Live Mail.
>  > > > >
>  > > 
> http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d_______________________________________________
>  > > > > Insight-users mailing list
>  > > > > Insight-users at itk.org
>  > > > > http://www.itk.org/mailman/listinfo/insight-users
>  > > > >
>  > > >
>  > >
>  > >
>  > > 
> ------------------------------------------------------------------------
>  > > Be one of the first to try Windows Live Mail.
>  > > 
> <http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d>
>  >
> 
> 
> ------------------------------------------------------------------------
> Be one of the first to try Windows Live Mail. 
> <http://ideas.live.com/programpage.aspx?versionId=5d21c51a-b161-4314-9b0e-4911fb2b2e6d>



More information about the Insight-users mailing list