I'm trying to binarize images of corn kernels using Otsu method, but some parts of the kernels are thresholded incorrectly. I also tried Gaussian blur but it doesn't really help.
Is there anyway to fix this? Thanks.
Here's my code:
img = io.imread("data/corn/IMG_4354.jpg")
img = imutils.resize(img, width=500)
gray = color.rgb2gray(img)
gray = filters.gaussian(gray, sigma=3)
binary = gray > filters.threshold_otsu(gray)
fig, axes = plt.subplots(ncols=3, figsize=(20,20))
axes = axes.ravel()
axes[0].axis('off')
axes[0].imshow(img)
axes[0].set_title("Input", fontsize=20)
axes[1].axis('off')
axes[1].imshow(gray, cmap='gray')
axes[1].set_title('gray', fontsize=20)
axes[2].axis('off')
axes[2].imshow(binary, cmap='gray')
axes[2].set_title('Binarized', fontsize=20)