When the background isn't that obvious
Sometimes, it isn't that obvious to identify the background. If the image background is relatively uniform, then you can use a global threshold value as we practiced before, using threshold_otsu()
. However, if there's uneven background illumination, adaptive thresholding threshold_local()
(a.k.a. local thresholding) may produce better results.
In this exercise, you will compare both types of thresholding methods (global and local), to find the optimal way to obtain the binary image we need.

Image loaded as
page_image
.
This exercise is part of the course
Image Processing in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the otsu threshold function
from skimage.____ import ____
# Obtain the optimal otsu global thresh value
global_thresh = ____(page_image)
# Obtain the binary image by applying global thresholding
binary_global = page_image ____ ____
# Show the binary image obtained
show_image(binary_global, 'Global thresholding')