I want to clearly identify and draw the contour of two adjacent liquid layer, the sample image is as shown in the link
sample image
This is what I have tried so far, but the result is far off.
import cv2
# Let's load a simple image with 3 black squares
image = cv2.imread('input/blood.png')
cv2.waitKey(0)
# Grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
tube_gray = cv2.GaussianBlur(gray, (7, 7), 0)
#edged = cv2.Canny(tube_gray, 45, 95)
edged = cv2.Canny(tube_gray, 58, 182)
# Find Canny edges
cv2.waitKey(0)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(9,9))
dilated = cv2.dilate(edged, kernel)
contours, hierarchy = cv2.findContours(dilated.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
cv2.imshow('Canny Edges After Contouring', edged)
cv2.waitKey(0)
print("Number of Contours found = " + str(len(contours)))
for cnt in contours:
print(cv2.contourArea(cnt))
# Draw all contours
# -1 signifies drawing all contours
cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
cv2.imshow('Contours', image)
cv2.waitKey(0)
cv2.destroyAllWindows()