-
Notifications
You must be signed in to change notification settings - Fork 0
Background Removal
Ciaran-OBrien edited this page Oct 24, 2018
·
1 revision
Following from our meeting yesterday, we suggested trying to remove the background of an image. I tested the following code on the cleaned image, which had a Sobel Edge Filter passed on it
contour_info = []
# RETR_LIST retrieves all of the contours without establishing any hierarchical relationships.
# CV_CHAIN_APPROX_SIMPLE compresses horizontal, vertical, and diagonal segments and leaves only their end points.
# We don't need all the contour details
_, contours, _ = cv2.findContours(converted, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
contour_info.append((contour,cv2.isContourConvex(contour),cv2.contourArea(contour), ))
contour_info = sorted(contour_info, key=lambda c: c[2], reverse=True)
max_contour = contour_info[0]# Here we create empty mask, then a draw filled polygon shape around it relative to the largest contour
# Mask is black, polygon is white
mask = np.zeros(converted.shape)
cv2.fillConvexPoly(mask, max_contour[0], (255))
plt.imshow(mask,cmap='gray')
plt.show()We can see below, that the mask has been able to leave behind a masked outline of the bus as part of the tested image. Following this, we need to look at testing this method on the sample images, where there is a certain amount of noise present which may prove to be difficult to deal with.
