= transform.resize(mask, (df_valid.img_height, df_valid.img_width))
mask
= filters.threshold_mean(mask) #threshold_isodata, threshold_otsu, threshold_li, threshold_mean etc.
threshold = mask > threshold
mask = mask.astype(np.int8) mask
Thresholding using scikit image (part of my kaggle submission code)
When I attempted segmentation problems and generated masks I faced a significant problem with thresholding parameters. If you have a mask or image with a very sparse pixel value all over then you won’t be able to see the real image rather it acts like a secret note which is only visible when you show it in sunlight.I searched for a way in my Kaggle Competition submission to convert a mask to a binary mask without randomly setting the threshold. lINK TO THE 80TH Place Notebook Here - https://www.kaggle.com/code/nishantbhansali/rank-80th-train-coat-hubmap-final-for-lb-part-3
my mask looked like this:
I was randomly trying out thresholds like 0.5, 0.70, . . . 0.14 . . . and it is almost impossible to do the same for every experiment. Rather I searched for a how-to convert masks to binary masks with an automated threshold. Then I stumbled upon thresholding on the scikit image and the tutorial is very simple to use any thresholding. Link >> from skimage.filters import threshold_minimum, threshold_isodata, threshold_li, threshold_mean, threshold_otsu
I tried all of them for my different experiments. And each of them had a different result. My final submission looked like this, which can smoothen a bit more this gave me a top leaderboard accuracy like a 0.78 Dice Score on LeaderBoard here.
More on different types of thresholding techniques :
The thresholding technique’s basic idea is —
- to find a threshold by performing some operation on the Image i.e. threshold = Function(Image)
- Binary_Image = Image > threshold
So it is like when we do mean thresholding it is like threshold = Mean(Image). Where in minimum thresholding, thresholding = Minimum(Image).
But the techniques like Otsu’s Threshold go beyond the ways of Minimum or mean to find the Threshold.