# Orientation of Bounding Boxes of Morphological Components

If I do a ...

components = MorphologicalComponents[img, 0.3, Method->"BoundingBox"];


followed by a ...

binCounts = BinCounts[Flatten[components]];


I find that there is a prime number binCounts. Regardless of padding and other edge effects, shouldn't each entry in binCounts be the product of two integers; viz. the height and width of a (non-overlapping) bounding box? Perhaps the sides of the bounding box aren't parallel to the axes? If so, can one ask MorphologicalComponents for bounding boxes that are?

To experiment, I picked an image from the documentation for MorphologicalComponents:

components = MorphologicalComponents[img, 0.3, Method -> "BoundingBox"];
components // Colorize


This image shows that the bounding boxes are aligned with the axes. Let's now select all components with a prime number of elements:

SelectComponents[components, PrimeQ[#Count] &] // Colorize


The only component that has a prime number of elements is the one that is partially overlapped. This means that the count for this particular component is not the product of the width and the height since the component is not rectangular.

This probably explains your problem as well.