I try to find the inner boundaries within this 8-bit grayscale image: img = cv2.imread("C:/users/XXX/test.png", -1) I've been playing around with various morphological operations but I can't seem to find any that work well. The most promising approach so far: After (simple) binarization I receive the following: img = (img > 0) * 1 img = img.astype('uint8') plt.imshow(img, cmap = "gray", vmin = 0, vmax = 1) plt.show() plt.close() Or, using mild blurring in advance: img = cv2.medianBlur(img, 3) img = (img > 0) * 1 img = img.astype('uint8') plt.imshow(img, cmap = "gray", vmin = 0, vmax = 1) plt.show() plt.close() Applying closing with an asymmetric kernel I then tried to further enhance the more-or-less horizontal lines: kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (15,3)) imgClose = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel) plt.imshow(imgClose, cmap = "gray", vmin = 0, vmax = 1) plt.show() plt.close() What I want to achieve (red line drawn by hand): Any idea how to get there? Continue reading...