[Insight-users] Perimeter Calculation via LabelImageToShapeLabelMapFilter

robert tamburo robert.tamburo at gmail.com
Wed Mar 2 12:22:07 EST 2011


I was looking at LabelImageToShapeLabelMapFilter as a way to calculate the
area and perimeter of labeled objects for computing
compactness/circularity*. I am confused about the perimeter calculation
though. It seems to be missing a factor of 2. My test was to create an image
(1x1 spacing) containing a 50x50 square resulting in a size (area) of 2500
as expected and a perimeter of 100 instead of 200 (results identical with
FullyConnected set to On/Off).

Can anyone closer to the perimeter calculator code comment on whether this
is expected behavior?

* The roundness calculation is new to me. Can someone describe the value
range? From the Insight Journal paper, it seems the range is 0 to something
greater than 1 with 1 indicating a perfect circle. Is that correct?

Thanks!

// Relevant code
  typedef itk::ShapeLabelObject<unsigned char, 2> LabelObjectType;
  typedef itk::LabelMap<LabelObjectType> LabelMapType;
  typedef itk::LabelImageToShapeLabelMapFilter<CharImageType, LabelMapType>
ShapeLabelFilterType;
  ShapeLabelFilterType::Pointer shapeFilter = ShapeLabelFilterType::New();
  shapeFilter->SetInput(tempImage);
  shapeFilter->SetBackgroundValue(0);
  shapeFilter->SetComputePerimeter(1);
  shapeFilter->Update();

  LabelMapType::Pointer labelMap = shapeFilter->GetOutput();
  for(unsigned int label = 1; label <= labelMap->GetNumberOfLabelObjects();
label++)
    {
    const LabelObjectType * labelObject = labelMap->GetLabelObject(label);
    std::cerr << "    label: " << label << std::endl;
    std::cerr << "    physical size: " << labelObject->GetPhysicalSize() <<
"   centroid: " << labelObject->GetCentroid() << std::endl;
    std::cerr << "    perimeter: " << labelObject->GetPerimeter() << "   eq
perimeter: " << labelObject->GetEquivalentPerimeter() << std::endl;
    std::cerr << "    eq radius: " << labelObject->GetEquivalentRadius() <<
std::endl;
    std::cerr << "    size: " << labelObject->GetSize() << std::endl;
    std::cerr << "    roundness: " << labelObject->GetRoundness() <<
std::endl;
    std::cerr << "    P^2/A: " << (labelObject->GetPerimeter() *
labelObject->GetPerimeter()) / labelObject->GetSize() << " should be: " <<
(50*4)*(50*4)/(50*50) << std::endl;
    std::cerr << "    P^2/4*PI*A: " << (labelObject->GetPerimeter() *
labelObject->GetPerimeter()) / (4 * 3.14 * labelObject->GetSize()) << "
should be: " << (50*4)*(50*4)/(4*3.14*50*50) << std::endl;
    }

// Output
    label: 1
    physical size: 2500   centroid: [74.5, 74.5]
    perimeter: 100   eq perimeter: 177.245
    eq radius: 28.2095
    size: 2500
    roundness: 1.77245
    P^2/A: 4 should be: 16
    P^2/4*PI*A: 0.318471 should be: 1.27389
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110302/c64163f0/attachment.htm>


More information about the Insight-users mailing list