Successfully segment areas I want, but how to determine the grayscale of these areas separately in original image instead of the binary? Tried find contours but it doesn't give me solid lines.
import opencv as cvimport numpy as npimg = imread(fileName)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)gray_blur = cv2.GaussianBlur(gray, (5, 5), 0)ret,thresh = cv.threshold(gray_blur,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)kernel = np.ones((15,15), np.uint8)close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)kernel = np.ones((8,8), np.uint8)opening = cv2.morphologyEx(close, cv2.MORPH_OPEN, kernel)cont_img = close.copy()contours, hierarchy = cv2.findContours(cont_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)loe= []for cnt in contours: area = cv2.contourArea(cnt) if area < 500 or area > 4000000: continue if len(cnt) < 5: continue ellipse = cv2.fitEllipse(cnt) loe.append(ellipse) cv2.drawContours(img, [cnt], 0, (0,255,0),2) cv2.ellipse(img, ellipse, 0, 5,2)cv2.namedWindow('img', cv2.WINDOW_NORMAL)cv2.resizeWindow('img', 1000, 750)cv2.imshow("img", img)
segmented:
original:
with contours: