Apply global thresholding
In this exercise, you'll transform a photograph to binary so you can separate the foreground from the background.
To do so, you need to import the required modules, load the image, obtain the optimal thresh value using threshold_otsu()
and apply it to the image.
You'll see the resulting binarized image when using the show_image()
function, previously explained.

Image loaded as
chess_pieces_image
.
Remember we have to turn colored images to grayscale. For that we will use the rgb2gray()
function learned in previous video. Which has already been imported for you.
This exercise is part of the course
Image Processing in Python
Exercise instructions
- Import the otsu threshold function.
- Turn the image to grayscale.
- Obtain the optimal threshold value of the image.
- Apply thresholding to the image.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import the otsu threshold function
from skimage.____ import ____
# Make the image grayscale using rgb2gray
chess_pieces_image_gray = ____(____)
# Obtain the optimal threshold value with otsu
thresh = ____(____)
# Apply thresholding to the image
binary = chess_pieces_image_gray ____ ____
# Show the image
show_image(binary, 'Binary image')