binary =cv2.adaptiveThreshold(cut, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 35, 10) # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (6, 6)) binary_close = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel) cv2.imwrite('roi_{}.jpg'.format(i), binary_close) read_binary = cv2.imread('roi_{}.jpg'.format(i)) The values in binary_close are only 255 and 0, however, some smaller values in read_binary such as 254.