[Insight-users] Drawing a circle on a binary image

Ivan Macia imacia at vicomtech.org
Fri Jun 11 07:17:05 EDT 2010


Hi,

I assume your image is 2D, and create the mask from scratch. Replace
constants by your values.
Didn't even try to compile this so there could be errors but you should get
the idea, you can try and tell me if it works

Regards

Iván


typedef unsigned char MaskPixelType;
const unsigned int Dimension = 2;
typedef itk::Image<MaskPixelType,Dimension> MaskImageType;

// Create mask from scratch, otherwise copy properties from input image

MaskImageType::Pointer mask = MaskImageType::New();

MaskImageType::RegionType::SizeType maskSize;
maskSize[0] = MY_IMAGE_SIZE_X;
maskSize[1] = MY_IMAGE_SIZE_Y;

MaskImageType::RegionType::IndexType maskIndex;
maskIndex.Fill(0);

MaskImageType::RegionType maskRegion;

maskRegion.SetSize( maskSize );
maskRegion.SetIndex( maskIndex );

mask->SetRegions( maskRegion );

MaskImageType::SpacingType maskSpacing;
maskSpacing.Fill( 1.0 );
mask->SetSpacing( maskSpacing );

mask->Allocate();
mask->FillBuffer( itk::NumericTraits<MaskPixelType>::Zero );

MaskImageType::PointType centerPoint;
centerPoint[0] = MY_CENTER_COORD_X;
centerPoint[1] = MY_CENTER_COORD_Y;

typedef itk::ImageRegionIteratorWithIndex<MaskImageType>  MaskIteratorType;

MaskIteratorType it( mask, mask->GetRequestedRegion() );
it.GoToBegin();

while( !it.IsAtEnd() )
{
  const MaskImageType::IndexType & index = it.GetIndex();

  if( ( index[0] * spacing[0] - centerPoint[0] ) * ( index[0] * spacing[0] -
centerPoint[0] ) + ( index[1] * spacing[1] - centerPoint[1] ) * ( index[1] *
spacing[1] - centerPoint[1] )
     <= MY_RADIUS * MY_RADIUS )
  {
     it.Set( itk::NumericTraits<MaskPixelType>::max() ); // or replace value
  }

  ++it;
}


2010/6/11 <arpitagrawal at iitb.ac.in>

> hey all,
> I want to draw a circle of a given radius and center on a binary image...I
> cannot get how to use EllipseSpatialObject to do the same...
> plz help..
>
> regards,
> Arpit
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100611/981f9cea/attachment.htm>


More information about the Insight-users mailing list