[Insight-users] itk::DiscreteGaussianImageFilter
Luis Ibanez
luis.ibanez at kitware.com
Mon, 26 Jan 2004 14:58:08 -0500
Hi Corinne,
The problem seems to be with your method for
checking whether the image is empty or not.
You can make a simpler test by just saving
the image to disk. For example the following
lines added to the ModelToImageRegistration
example will dump the image to a file.
642a643,648
> typedef itk::ImageFileWriter< ImageType > WriterType;
> WriterType::Pointer writer = WriterType::New();
> writer->SetInput( gaussianFilter->GetOutput() );
> writer->SetFileName("sphere.mhd");
> writer->Update();
>
In your code you are using a manually set index.
You should use ITK iterators for this purpose.
Please take a look at the chapter on iterators
on the Software guide.
http://www.itk.org/ItkSoftwareGuide.pdf
Chapter 11, pdf-page 486.
---
Your code should look like:
typedef itk::ImageRegionConstIterator< ImageType > Iterator;
Iterator it( image, image->GetBufferedRegion() );
it.GoToBegin();
while( !it.IsAtEnd() )
{
if( it.Get() != )
{
std::cout << it.GetIndex() << std::endl;
}
++it;
}
Regards,
Luis
-------------------------------
--------------------------
Corinne Mattmann wrote:
> Hi,
>
> I would like to create an image containing a sphere. To achieve this I'm
> using itkEllipseSpatialObject, itkSpatialObjectToImageFilter and
> itkDiscreteGaussianImageFilter (see attached code at the bottom). But it
> seems that I get an image just consisiting of zeros.
> That's why I took the example file ModelToImageRegistration1.cxx and
> inputed the attached code at line 641 (just after
> gaussianFilter->Update();) but with the same result: an empty image.
>
> What am I doing wrong? Or is there might something wrong with the
> itkDiscreteGaussianImageFilter?
>
> Thanks,
> Corinne
>
>
> The code inputed at line 641:
>
> ImageType::IndexType index;
> index[0] = 0;
> index[1] = 0;
> int i=0;
> while((int)gaussianFilter->GetOutput()->GetPixel(index)==0){
> i++;
> index[0] = i%size[0];
> index[1] = floor((double)i/size[0]);
> if (i>=size[0]*size[1]){
> cout << "Image consists just of zeros!" << endl;
> break;
> }
> }
> for (int j=i; j<i+100; j++){
> if (j<size[0]*size[1]){
> index[0] = j%size[0];
> index[1] = ((int)floor((double)j/size[0])) % size[0];
> index[2] = floor((double)j/(size[0]*size[1]));
> cout << "Pixel sphere1 at " << index << ": "
> << (int)gaussianFilter->GetOutput()->GetPixel(index) << endl;
> }
> else
> break;
> }
>
>
>
> My approach to get a sphere:
>
> ImageType::SizeType size;
> size[0] = 50;
> size[1] = 50;
> size[2] = 50;
> // ImageType::SpacingType spacing;
> double spacing[3];
> spacing[0] = 1;
> spacing[1] = 1;
> spacing[2] = 1;
>
> typedef itk::EllipseSpatialObject<Dimension> EllipseType;
> EllipseType::Pointer sphere1_spatialObject = EllipseType::New();
> sphere1_spatialObject->SetRadius(10);
> sphere1_spatialObject->SetSpacing(spacing);
> typedef itk::SpatialObjectToImageFilter<EllipseType, ImageType>
> SpatialObjectToImageFilterType;
> SpatialObjectToImageFilterType::Pointer sphere1_filter =
> SpatialObjectToImageFilterType::New();
> sphere1_filter->SetInput(sphere1_spatialObject);
> sphere1_filter->SetSize(size);
> sphere1_filter->SetInsideValue(127);
> sphere1_filter->SetOutsideValue(0);
> sphere1_filter->Update();
> typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType>
> GaussianFilterType;
> GaussianFilterType::Pointer sphere1_GaussianFilter =
> GaussianFilterType::New();
> sphere1_GaussianFilter->SetInput(sphere1_filter->GetOutput());
> const double variance = 1;
> sphere1_GaussianFilter->SetVariance(variance);
> sphere1_GaussianFilter->Update();
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>