higra / Higra

Hierarchical Graph Analysis
Other
97 stars 20 forks source link

`hg.match_pixels_image_2d` fails when nothing matches between the two boundary maps #269

Closed lapertor closed 11 months ago

lapertor commented 1 year ago

When giving two boundary maps to hg.match_pixels_image_2d, but there are no boundaries that match, the function hg.cpp._get_bipartite_matching_graph_contour_image_2d (used inside the code of hg.match_pixels_image_2d) basically returns that nothing matched, notably with an empty weights on which a np.max operation is performed afterwards, causing the following error:

line 46, in dummy_function
    sources, targets = hg.match_pixels_image_2d(ucm_th, bmap, max_distance=params["max_dist"])
line 345, in match_pixels_match
    matched_edges = hg.bipartite_graph_matching((sources, targets, num_nodes1 + num_nodes2), (weights * 1000).astype(np.int64))
line 144, in bipartite_graph_matching
    very_large_weight = np.max(edge_weights) * 1000
line 2705, in amax
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
line 87, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation maximum which has no identity