I am working with the following image:
And I would like to make it binary, however, as can be seen in the image, there are different brightness' of grey spots. I would like for all the grey spots to be captured in the binary at the exact size.
If I apply 1 (one) threshold to the image, I get one of the following outcomes:'
- Large threshold (t=0.8): More of the lighter spots shown in the binary, BUT the darker spots are then made larger than in the original.
- Smaller threshold (t=0.7): Less of the lighter spots shown in binary, BUT the darker spots appear as their exact size.
Is there a way to apply multiple thresholds to one image according to the colour of the pixel? So to apply a larger threshold to the "lighter" pixels and a smaller threshold to the "darker" pixels?
This is my code with the threshold: t = 0.8
import skimage.io
import skimage.viewer
import skimage
import skimage.io
# Read image.TIF:
image = skimage.io.imread(fname="<source-directory>")
image[2,1]= 1.0
# Process the file
gray_image = skimage.color.rgb2gray(image)
# Blur the image to denoise
blurred_image = skimage.filters.gaussian(gray_image, sigma=5)
# Adding threshold, t:
t = 0.8
binary_mask = blurred_image < t
# Save the file to another location:
skimage.io.imsave(fname="<target-directory>", arr = binary_mask)
Any help is much sprreciated!