【问题标题】:BoundingBox different in Python/MATLABPython / MATLAB中的BoundingBox不同
【发布时间】:2021-10-15 05:36:29
【问题描述】:

在 MATLAB 中我有以下代码:

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

并且 v 返回: [194.5000, 156.5000, 378.0000, 154.0000; 325.5000、342.5000、160.0000、160.0000]

在 Python 中:

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

这一次 v 返回:array([[156, 194, 310, 572], [342, 325, 502, 485]])

有些数字很相似,但我不知道它们的真正含义。 ¿ 有谁知道我怎样才能在 MATLAB 中获得相同的结果?

【问题讨论】:

    标签: python matlab opencv scikit-image


    【解决方案1】:

    这两种格式的输出格式有些不同,我想同样的可能会让你感到困惑

    OpenCV 输出:

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

    Matlab 输出:

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

    如果要复制这些值,只需在 matlab 输出中将高度和宽度参数相加即可

    请注意:我可能混淆了 2 个轴。但是加法的基本概念是一样的

    【讨论】:

    • 我意识到,虽然 MATLAB 为您提供第三和第四列作为宽度和高度,但 python 为您提供 min_col 和 max_col,并且前 2 列的位置发生了变化。无论如何,谢谢!
    • 但这并不能解释那半像素是从哪里来的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 2011-12-17
    • 2016-02-10
    • 2019-06-24
    • 2017-12-10
    • 1970-01-01
    • 2021-10-17
    相关资源
    最近更新 更多