I have an image showed below (this image is a result of pre-processing of original image I had):
What I am trying to do is to detect the contour for the Black region bounded by 2 white regions (please note that white regions are not always solid and there could be 2, 3,... disconnected white region on top - for most of pictures the white regions are continuous; however, there are some examples where top white region is not continuous - Please see update section of my question to see example of non-continuous region)
Do you have any suggestion as how I can detect the boundary of black region and separate the black region?
========= UPDATE Requested by Micka ========
Example of non-continuous white region (this is happening only on top layer) - bottom layer is always continues solid white region
In this case like the picture showed above, I am okay with selecting a region like the one I showed below
ideal selection
Original PHOTO I also included the original image for the above pre-processed image below in a case you are interested to work on pre-processing it. The pre-processing code I used and ended up with the image above is showed below:
img = cv2.imread('....tif')
# convert to grayscale
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# threshold
thresh = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY)[1]
# apply morphology
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (1,5))
morph = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (29,1))
morph = cv2.morphologyEx(morph, cv2.MORPH_CLOSE, kernel)