Otsu's Method Thresholding Making A 'shroud'
Solution 1:
You do not need to manually find a sweet spot! Let OpenCV do it for you!
OpenCV has an adaptive thresholding algorithm exactly from problems like this, called adaptiveThreshold
This function divides the image into multiple sub-images, and thresholds each one individually. This means that it will find a nice threshold value for each part of the image and give you a nice and uniformly lit image. See this example.
Try this:
th3 = cv.adaptiveThreshold(blurred,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv.THRESH_BINARY,11,2)
Update: Functions like these do not work perfectly out of the box. If it still creates artefacts like salt and pepper noise, you can try:
- Significantly increasing the
blockSize
. This can ensure that each block has a letter inside, which will hopefully mean the threshold will be chosen better. (e.g. Dividing the image into25
blocks instead of100
. Ablocksize
of11
pixels is very small.) - First apply a blurring filter to ease out the bad spots creating the seasoning noise. (With the image name
blurry
I imagine that you've done this already. - First the simple threshold function to just removes some noise. For example setting all pixels above 5 and below 100 equal to zero. Then after that apply the
adaptiveThreshold
. - Follow @Mark`s advice by subtracting a blurred image from the original image. (See this thread)
I hope this helps!
Solution 2:
Instead of using Otsu's method try global thresholding method.
thresh_value = 50
ret,thresh= cv2.threshold(blurred,thresh_value,255,cv2.THRESH_BINARY)
change the thresh_value
parameter until you get the result you want.
Get to know more about thresholding techniques please refer the documentation.
Post a Comment for "Otsu's Method Thresholding Making A 'shroud'"