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). <div>
<br></div><div>Can anyone closer to the perimeter calculator code comment on whether this is expected behavior?</div><div><br></div><div>* 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?</div>
<div><br></div><div>Thanks!</div><div><br></div><div>// Relevant code</div><div><div><div><div> typedef itk::ShapeLabelObject<unsigned char, 2> LabelObjectType;</div><div> typedef itk::LabelMap<LabelObjectType> LabelMapType;</div>
<div> typedef itk::LabelImageToShapeLabelMapFilter<CharImageType, LabelMapType> ShapeLabelFilterType;</div><div> ShapeLabelFilterType::Pointer shapeFilter = ShapeLabelFilterType::New();</div><div> shapeFilter->SetInput(tempImage);</div>
<div> shapeFilter->SetBackgroundValue(0);</div><div> shapeFilter->SetComputePerimeter(1);</div><div> shapeFilter->Update();</div><div> </div><div> LabelMapType::Pointer labelMap = shapeFilter->GetOutput();</div>
<div> for(unsigned int label = 1; label <= labelMap->GetNumberOfLabelObjects(); label++)</div><div> {</div><div> const LabelObjectType * labelObject = labelMap->GetLabelObject(label);</div><div> std::cerr << " label: " << label << std::endl;</div>
<div> std::cerr << " physical size: " << labelObject->GetPhysicalSize() << " centroid: " << labelObject->GetCentroid() << std::endl;</div><div> std::cerr << " perimeter: " << labelObject->GetPerimeter() << " eq perimeter: " << labelObject->GetEquivalentPerimeter() << std::endl;</div>
<div> std::cerr << " eq radius: " << labelObject->GetEquivalentRadius() << std::endl;</div><div> std::cerr << " size: " << labelObject->GetSize() << std::endl;</div>
<div> std::cerr << " roundness: " << labelObject->GetRoundness() << std::endl;</div><div> std::cerr << " P^2/A: " << (labelObject->GetPerimeter() * labelObject->GetPerimeter()) / labelObject->GetSize() << " should be: " << (50*4)*(50*4)/(50*50) << std::endl;</div>
<div> 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;</div>
<div> }</div></div></div><div><div><br></div><div>// Output</div><div><div> label: 1</div><div> physical size: 2500 centroid: [74.5, 74.5]</div><div> perimeter: 100 eq perimeter: 177.245</div><div> eq radius: 28.2095</div>
<div> size: 2500</div><div> roundness: 1.77245</div><div> P^2/A: 4 should be: 16</div><div> P^2/4*PI*A: 0.318471 should be: 1.27389</div></div><div><br></div><div><br></div></div></div>