I'm having the following problem: I cannot find a way to access each connected component's first and last pixels which were obtained through cv2.connectedComponentsWithStats function of OpenCV in Python. What i want to do, is to suppress the connected components whose first pixel does not coincide with the its last one (hence, unsevered) . Any ideas?
Here's the code calling cv2.connectedComponentsWithStats and suppressing too small and too big connected components:
#Find connected components
nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(edges,connectivity=8)
sizes = stats[1:, -1];
nb_components = nb_components - 1
#remove small and large connected components
final_labels = np.array([])
edges_filtered = np.zeros((output.shape),np.uint8)
for i in range(0, nb_components):
if sizes[i] >= MIN_CC_SIZE and sizes[i] <= MAX_CC_SIZE:
edges_filtered[output == i + 1] = 255
cv2.imshow("edges_filtered",edges_filtered)
cv2.waitKey()