I'm using scikit-image for computer vision. I will use find contours to obtain the contours of the grayscale image input but the list returned contain the contours in the image all in the first location. The result that I want to obtain is the only out contour of the image, for this reason I try to separate the contours with a for cycles but it requires very long time and the result is not good. Can anyone help me? The code is reported below:
import numpy as np
from skimage.io import imread
from skimage.measure import moments, moments_hu, find_contours, approximate_polygon
from skimage.feature import canny
from matplotlib import pyplot as plt
#%% Opening image section
reference_image = imread('referenceImage.jpg', as_gray= True)
reference_contours = find_contours(reference_image, 0.8, fully_connected='high')
first = True
added = False
reference_contours_list = []
for contours in reference_contours:
for con in contours:
if first:
first = False
reference_contours_list.append(np.array(np.array([con])))
else:
for index, past_con in enumerate(reference_contours_list):
for past_c in past_con:
if con[0] in range(int(round(past_c[0])) - 1, int(round(past_c[0])) + 2):
reference_contours_list[index] = np.append(reference_contours_list[index], np.array(np.array([con])), axis=0)