No account yet ?
Tested in Anaconda and Python 3.7
# Python program to illustrate # Otsu thresholding type on an image # organizing imports import cv2 from matplotlib import pyplot as plt import matplotlib.image as mpimg # path to input image is specified and # image is loaded with imread command image_originale = cv2.imread('cat-threshimages.jpg') plt.imshow(image_originale) plt.axis('off') plt.show() # cv2.cvtColor is applied over the # image input with applied parameters # to convert the image in grayscale img = cv2.cvtColor(image_originale, cv2.COLOR_BGR2GRAY) plt.imshow(img, 'gray') plt.axis('off') plt.show() # applying Otsu thresholding # as an extra flag in binary # thresholding th, thresh1 = cv2.threshold(img, 50, 255, cv2.THRESH_TRUNC) # the window showing output image # with the corresponding thresholding # techniques applied to the input image plt.imshow(thresh1, 'gray') plt.axis('off') plt.show() mpimg.imsave('CatTruncThresholding-50.jpg', thresh1, cmap='gray') # applying Otsu thresholding # as an extra flag in binary # thresholding th, thresh1 = cv2.threshold(img, 100, 255, cv2.THRESH_TRUNC) # the window showing output image # with the corresponding thresholding # techniques applied to the input image plt.imshow(thresh1, 'gray') plt.axis('off') plt.show() mpimg.imsave('CatTruncThresholding-100.jpg', thresh1, cmap='gray') # applying Otsu thresholding # as an extra flag in binary # thresholding th, thresh1 = cv2.threshold(img, 150, 255, cv2.THRESH_TRUNC) # the window showing output image # with the corresponding thresholding # techniques applied to the input image plt.imshow(thresh1, 'gray') plt.axis('off') plt.show() mpimg.imsave('CatTruncThresholding-150.jpg', thresh1, cmap='gray') # applying Otsu thresholding # as an extra flag in binary # thresholding th, thresh1 = cv2.threshold(img, 200, 255, cv2.THRESH_TRUNC) # the window showing output image # with the corresponding thresholding # techniques applied to the input image plt.imshow(thresh1, 'gray') plt.axis('off') plt.show() mpimg.imsave('CatTruncThresholding-200.jpg', thresh1, cmap='gray')
Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !
Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License