Aplica un umbral global
En este ejercicio, vas a transformar una fotografía a binaria para poder separar el primer plano del fondo.
Para ello, necesitas importar los módulos necesarios, cargar la imagen, obtener el valor de umbral óptimo usando threshold_otsu() y aplicarlo a la imagen.
Verás la imagen binarizada resultante usando la función show_image(), explicada anteriormente.
Imagen cargada como
chess_pieces_image.
Recuerda que hay que convertir las imágenes en color a escala de grises. Para eso usaremos la función rgb2gray() que viste en el video anterior. Ya la hemos importado por ti.
Este ejercicio forma parte del curso
Procesamiento de Imágenes en Python
Instrucciones del ejercicio
- Importa la función de umbral de Otsu.
- Convierte la imagen a escala de grises.
- Obtén el valor de umbral óptimo de la imagen.
- Aplica el umbral a la imagen.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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')