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.
Deze oefening maakt deel uit van de cursus
Image Processing in Python
Oefeninstructies
- Import the otsu threshold function.
- Turn the image to grayscale.
- Obtain the optimal threshold value of the image.
- Apply thresholding to the image.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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')