I am trying to obtain an image mask with multiple level of threshold meaning considering on the intensity of the pixels I want to threshold the image - white for brightest regions, grey for slightly less brighter regions and black for relatively darker regions. I have come across various articles about multilevel otsu threshold but I could not find an implementation I could use as reference. Once I have these masks I want to perform the bitwise_and on these mask to retrieve original image area for white and grey regions. Is that possible?
Currently, I am using ret, thresh_ = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
for getting the masks.
I have tried to explicitly set the values using if statements.
if(thresh_ <=80):
thresh_ = 0
elif(thresh_ >80 & thresh_ <=160):
thresh_ = 150
else:
thresh_ = 255
But it didn't work and it gave an error- The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
for file in glob.glob(path):
img = cv2.imread(file)
#edge detection
canny = auto_canny(img)
#Dilation(Morphological function to increase edge width)
img_dilate = cv2.dilate(canny, (3,3), iterations = 1)