I would like to extract logos from golf balls for further image processing.
I have already tried different methods.
Any solution is welcome. Please forgive my English. Also, I am quite a beginner in programming. Probably there is a very simple solution to my problem but I thank you in advance for your help.
Here are 2 example images first the type of images from which the logos should be extracted and then how the image should look like after extraction.
Thank you very much. Best regards T
This is essentially "adaptive" thresholding, except this approach doesn't need to threshold. It adapts to the illumination, leaving you with a perfectly fine grayscale image (or color, if extended to do that).
illumination:
normalized (and scaled a bit):
thresholded with Otsu:
def process(im, r=80):
med = cv.medianBlur(im, 2*r+1)
with np.errstate(divide='ignore', invalid='ignore'):
normalized = np.where(med <= 1, 1, im.astype(np.float32) / med.astype(np.float32))
return (normalized, med)
normalized, med = process(ball1, 80)
# imshow(med)
# imshow(normalized * 0.8)
ret, thresh = cv.threshold((normalized.clip(0,1) * 255).astype('u1'), 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
# imshow(thresh)