Problem calculating oriented bounding box, itk::ShapeLabelObject

Dear all,

I need the size of the oriented bounding box of a mask.
I created a shape label object and extracted already some attributes (like nr. of pixels etc), what works pretty fine.
Now I wanted to get the size of the oriented bounding box. But whatever I do and no matter which object I use, I always get the result [0, 0, 0]
Is there a trick?

Thanks a lot for your answer.

Regards

Elli

My code:

    typedef itk::CastImageFilter<ImageType, intImage> CastFilterType;
    typedef itk::CastImageFilter<ImageType, uCharImage> uCharCastFilterType;
    typedef itk::ConnectedComponentImageFilter <intImage, intImage> ConnectedComponentFilterType;
    typedef itk::LabelImageToShapeLabelMapFilter<intImage> LabelImageToShapeLabelMapFilterType;

    typedef int LabelType;
    typedef itk::ShapeLabelObject<LabelType, R> ShapeLabelObjectType;
    typedef itk::LabelMap<ShapeLabelObjectType> LabelMapType;
typename ConnectedComponentFilterType::Pointer connectedComponentImageFilter = ConnectedComponentFilterType::New();
connectedComponentImageFilter->SetInput(castFilter->GetOutput());
connectedComponentImageFilter->Update();
/*!
With the label image to shape label map filter the mask is converted to a labeled image
*/
typename LabelImageToShapeLabelMapFilterType::Pointer labelImageToShapeLabelMapFilter = LabelImageToShapeLabelMapFilterType::New();
labelImageToShapeLabelMapFilter->SetInput(connectedComponentImageFilter->GetOutput());
labelImageToShapeLabelMapFilter->SetComputePerimeter(true);
labelImageToShapeLabelMapFilter->Update();

LabelMapType *labelMap = labelImageToShapeLabelMapFilter->GetOutput();
labelMap->Update();
/*!
For every connected component a labelObject is created
Because we are only interested in the object with the label one, we check the label number
*/
for(unsigned int n = 0; n < labelMap->GetNumberOfLabelObjects(); n++){
    ShapeLabelObjectType *labelObject = labelMap->GetNthLabelObject(n);
    int labelNr = labelObject->GetLabel();
    if(labelNr ==1){

#ifdef _WIN32
volume = labelObject->GetPhysicalSize();
principalMoments = labelObject->GetPrincipalMoments();
nrPixels = labelObject->GetNumberOfPixels();
surface = labelObject->GetNumberOfPixelsOnBorder()imageSpacingXimageSpacingY*imageSpacingZ;
std::cout << “nr Pixels border” << labelObject->GetOrientedBoundingBoxOrigin() << std::endl;

It’s not enabled by default. Did you enable it?

More Specifically, it looks like you need to call the following method:
virtual void itk::LabelImageToShapeLabelMapFilter< TInputImage, TOutputImage >::ComputeOrientedBoundingBoxOn ( )
to enable the computations of the oriented bounding boxes.

1 Like

No, I did not enable it. I only did:

labelObject->GetOrientedBoundingBoxVertices() or
labelObject->GetOrientedBoundingBoxSize()

How can I enable it? I could not find anything in the documentation or I
looked for the wrong information.

Thanks in advance

Elli

Hi Elli

As Bradley said :

You have to set the computation enabled on the filter that gives you the label object as :
MyFilter->ComputeOrientedBoundingBoxOn() ;
or
MyFilter->SetComputeOrientedBoundingBox(true);

HTH,

Tim

1 Like