# How to calculate the sides of the bounding boxes

Good evening everyone,

My question will sound stupid and maybe it is but honestly I don’t know how to do it.

I would like to measure the average size of my particles by using the bounding boxes. In the “features selection” I can selection “bounding box maximum” and “bounding box minimum” which will give me the coordinates of the top left and bottom right corners of the bounding box.

What I would like to do is to find a way to calculate the length of the sides of this bounding box but I can’t find anything that would give me the right answer, does someone happen to know a way to do it please ?

Thanks a lot !

Hello @Antoine_Cure,

maybe a word of caution, first. If you enable bounding box coordinates in the feature selection step, then you should be aware those are used in the classification step as well (unless you disable it via the subset features button in training). The danger with those location-based features is that the classifier will try to learn something in terms of absolute coordinates in the image. This makes sense only rare cases. So yeah, usually you want to disable it.
To make it a little more confusing, ilastik will export the minimium and maximum bounding box coordinates in any case…

Good, so now to the original question.

``````Image coordinate system:

0----------------> x (_0)
|
|    Bounding box minimum
|      m---------------------------
|      |                           |
|      |                           |
|      |                           |
|       ---------------------------M
|                           Bounding box maximum
v

y (_1)
``````

So… okay in this wonderful sketch (I hope it renders correctly for you) the `m` is the Bounding box minimum, the `M` represents the maximum of the bounding box. The suffix `_0` in the table corresponds to the x-value, `_1` to `y`.
So in order to get the width and the height of the bounding box you’d calculate `Maximum_0 - Minimum_0`, and `Maximum_1 - Minimum_1`, respectively.

Does that make sense?

Cheers
Dominik

Hello Dominik,

Indeed that’s easy drawn like this, I don’t know why I thought the bounding box could be tilted so it was impossible to calculate the side

Anyway thanks a lot !

About the first part of your message, what kind of danger are you referring to ? Does it mean that the bounding boxes could give wrong values at some point ?

Hmmm I mean that those coordinates are absolute pixel coordinates. So what could you learn there is hat some objects that have certain mininmum bounding box x value belong to a certain class. So that this number in pixel coordinates has a meaning. I mean there could be the situation that you’d actually expect some class only in the right half of the image… Something like that. Then it would make sense. But if you’re objects are all over the image, and the position does not hold any predictive value, then such location features should not be included. This is also why there is this “all excluding location” button in the feature selection there…

Ho ok I understand, but let’s assume I absolutely need those coordinates to calculate the average size of my particles, how should I proceed ?

Or maybe is there a more convenient way of calculating the average size of particles, like the diameter or some other features ?

Maybe it could be good to choose the “pincipal components of the object” or “Radii of the object” but the results are eigenvalues, I don’t really know how to translate that into real length