I have performed some segmentation task and enumerated the extracted blobs using connectedComponents()
. This results in a single channel image with 32bit depth (CV_32S) containing the labels of the extracted objects.
# Result of my segmentation process:
# A binary mask of extracted objects.
mask = ...
# Create ids of connected components.
n_components, component_ids = cv.connectedComponents(mask)
# A lookup to map component ids to some (numeric) category ids.
# It has the form of { component_id: category }
lookup = ...
Note that in addition to the mask of extracted objects, a lookup
that maps components to some (problem specific) categories is available.
The question: How to apply lookup
to component_ids
? Intuitively, I would have used OpenCV's LUT(). However, this function is limited to 256 values. In my case, n_components
can be larger than 256, which is why I think LUT() is not the right method to use here. Any suggestions on how to proceed?