def img_thresholding(img, type): show_image(img) img_grayscale = color.rgb2gray(img) if type == 'global': thresh = threshold_otsu(img_grayscale) else: thresh = threshold_local(img_grayscale, block_size=35, offset=10) img_binary = img_grayscale > thresh img_binary2 = img_grayscale < thresh show_image(img_binary) show_image(img_binary2)
import sys import numpy as np sys.path.append('./helpers') from settings import show_image, nda_import_image nda_flipped_horiz_vert_seville = nda_import_image( './dataset/chapter 1/sevilleup(2).jpg') nda_flipped_horiz_seville = np.flipud(nda_flipped_horiz_vert_seville) show_image(nda_flipped_horiz_seville) nda_seville = np.fliplr(nda_flipped_horiz_seville) show_image(nda_seville)
import sys from skimage import data, color sys.path.append('./helpers') from settings import show_image img_rocket = data.rocket() img_grey_scaled_rocket = color.rgb2gray(img_rocket) show_image(img_rocket) show_image(img_grey_scaled_rocket)
> Import the appropriate thresholding and rgb2gray() functions. > Turn the image to grayscale. > Obtain the optimal thresh. > Obtain the binary image by applying thresholding. """ import sys from skimage.filters import try_all_threshold, threshold_li from skimage.color import rgb2gray from matplotlib import pyplot as plt sys.path.append('./helpers') from settings import nda_import_image, show_image str_tools_image_path = './dataset/chapter 1/shapes52.jpg' img_tools = nda_import_image(str_tools_image_path) def apply_thresholding_test(img): img_grayscale = rgb2gray(img) fig, ax = try_all_threshold(img_grayscale, verbose=False) plt.show() apply_thresholding_test(img_tools) img_tools_grayscale = rgb2gray(img_tools) li_thresh = threshold_li(img_tools_grayscale) img_tools_binary = img_tools_grayscale > li_thresh show_image(img_tools_binary)
colored images to grayscale. For that we will use the rgb2gray() function learned in previous video. Which has already been imported for you. Instructions: > Import the otsu threshold function > Make the image grayscale using rgb2gray > Obtain the optimal threshold value with otsu > Apply thresholding to the image > Show the image """ import sys from skimage.filters import threshold_otsu from skimage import color sys.path.append('./helpers') from settings import show_image, nda_import_image img_chess_pieces = nda_import_image('./dataset/chapter 1/bw.jpg') show_image(img_chess_pieces) img_chess_pieces_gray = color.rgb2gray(img_chess_pieces) thresh = threshold_otsu(img_chess_pieces_gray) img_binary = img_chess_pieces_gray > thresh img_binary2 = img_chess_pieces_gray < thresh show_image(img_binary) show_image(img_binary2)