# Problem calculating oriented bounding box, itk::ShapeLabelObject

**URL:** https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455
**Category:** Beginner Questions
**Created:** [November 25, 2017, 6:16pm UTC](https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455 "2017-11-25T18:16:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Elli](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/58f4c7/32.png) [@Elli](https://discourse.itk.org/u/Elli)
#### Post date: [November 25, 2017, 6:16pm UTC](https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455/1 "2017-11-25T18:16:32Z")

</div>

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()_imageSpacingX_imageSpacingY\*imageSpacingZ;  
std::cout \<\< “nr Pixels border” \<\< labelObject-\>GetOrientedBoundingBoxOrigin() \<\< std::endl;

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [November 25, 2017, 6:19pm UTC](https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455/2 "2017-11-25T18:19:13Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Elli](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/58f4c7/32.png) [@Elli](https://discourse.itk.org/u/Elli)
#### Post date: [November 28, 2017, 2:57pm UTC](https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455/3 "2017-11-28T14:57:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)
#### Post date: [November 29, 2017, 8:43am UTC](https://discourse.itk.org/t/problem-calculating-oriented-bounding-box-itk-shapelabelobject/455/4 "2017-11-29T08:43:27Z")

</div>

Hi Elli

As Bradley said :

> [@blowekamp](#):
>
> 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.

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
