[Insight-users] Cylinder SpatialObject & Image.

kent williams nkwmailinglists at gmail.com
Thu Aug 28 17:43:57 EDT 2008


We want to highlight a cylinder centered on a particular location in a
3D volume.  I've written the function given below to do this.  As it
stands, it looks as though setting the offset in the transform doesn't
work -- the cylinder shows up in only the last slice in the lower left
corner of the view, i.e. 0,0 in voxel space.  It should be somewhere
near the center of the image.

Apparently, something is screwy -- either the SpatialObject's IsInside
function isn't taking the ObjectToWorld tranform into account, or the
itk::OrientedImage::TransformIndexToPhysicalPoint doesn't the work as
I think it should.

Any ideas what I'm doing wrong?

typedef itk::OrientedImage<short,3> SImageType;
typedef itk::RGBPixel<unsigned char> RGBPixelType;
typedef itk::Image<RGBPixelType,3> RGBImageType;

RGBImageType::Pointer
MakeBrandedDebugImage(SImageType::Pointer &in,
                      acpcmodelDefinition &mDef,
                      const PointType &pt,
                      double height,radius,
                      const char *fname)
{
  itk::CylinderSpatialObject::Pointer cylinder =
    itk::CylinderSpatialObject::New();
  cylinder->SetHeight(mDef.GetRPHeight());
  cylinder->SetRadius(mDef.GetRPRadius());
  cylinder->SetHeight(height);
  cylinder->SetRadius(radius);

  itk::CylinderSpatialObject::TransformType::OutputVectorType v;
  v[0] = pt[0]; v[1] = pt[1]; v[2] = pt[2];
  cylinder->GetObjectToWorldTransform()->SetOffset(v);
  cylinder->ComputeObjectToWorldTransform();

  RGBImageType::Pointer rgbImage =
    itkUtil::AllocateImageFromRegionAndSpacing<SImageType,RGBImageType>
    (in->GetLargestPossibleRegion(),in->GetSpacing());
  rgbImage->SetDirection(in->GetDirection());
  rgbImage->SetOrigin(in->GetOrigin());

  itk::ImageRegionIterator<RGBImageType>
    rgbIt(rgbImage,rgbImage->GetLargestPossibleRegion());
  itk::ImageRegionIterator<SImageType>
    sIt(in,in->GetLargestPossibleRegion());

  for(;!sIt.IsAtEnd(); ++rgbIt,++sIt)
    {
    SImageType::IndexType index = sIt.GetIndex();
    SImageType::PointType p;
    in->TransformIndexToPhysicalPoint(index,p);
    RGBPixelType pixel;
    unsigned char charVal(ShortToUChar(sIt.Value(),minPixel,maxPixel));
    if(cylinder->IsInside(p))
      {
      pixel.SetRed(255);
      }
    else
      {
      pixel.SetRed(charVal);
      }
    pixel.SetGreen(charVal);
    pixel.SetBlue(charVal);
    rgbIt.Set(pixel);
    }
  return rgbImage;
}


More information about the Insight-users mailing list