Zyder
Zyder

Reputation: 33

BoundingBox different in Python/MATLAB

In MATLAB I have the following code:

props = regionprops(bw,'BoundingBox');
v = cat(1, props.BoundingBox);

and v returns this: [194.5000, 156.5000, 378.0000, 154.0000; 325.5000, 342.5000, 160.0000, 160.0000]

In Python:

label_img = label(bw, connectivity = bw.ndim)
regions = regionprops(label_img)
v = np.array([p.bbox for p in regions]).reshape(2,4)

and this time v returns: array([[156, 194, 310, 572], [342, 325, 502, 485]])

Some numbers are similar but I don't know what they really mean. ¿Does anyone knows how can I get the same result in MATLAB?

Upvotes: 1

Views: 149

Answers (1)

veedata
veedata

Reputation: 1228

The output formats for both of these are a bit different and I presume the very same might be confusing you

OpenCV output:

[156, 194, 310, 572] -> [min_x, min_y, max_x, max_y]

Matlab output:

[194.5000, 156.5000, 378.0000, 154.0000] -> [min_y, min_x, height, width]

If you want to replicate the values, it is simply the matter of adding up the height and width parameters in the matlab output

Please note: I might have mixed up the 2 axes. But the basic concept of addition remains the same regardless

Upvotes: 1

Related Questions