Pas encore de compte ?
Testé sous Anaconda et Python 3.7
import cv2 import matplotlib.pyplot as plt import matplotlib.image as mpimg def threshold_tozero(img): ret1, thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO) ret2, thresh2 = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO_INV) return thresh1, thresh2 if __name__ == '__main__': imgfile = 'cat-threshimages.jpg' try: img = cv2.imread(imgfile) img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) except cv2.error: print("Add image to args or in the code.") exit() binary_image1, binary_image2 = img > threshold_tozero(img) plt.imshow(binary_image1, cmap='gray') plt.axis('off') plt.show() mpimg.imsave('CatTozeroThresholding.jpg', binary_image1, cmap='gray') plt.imshow(binary_image2, cmap='gray') plt.axis('off') plt.show() mpimg.imsave('CatTozeroInvThresholding.jpg', binary_image2, cmap='gray')
Bienvenu, je m’appelle Eric Soupet et je suis l'administrateur du site elodees.com. elodees.com est un état de l'art de l'Intelligence Artificielle et se veut collaboratif, vous pouvez dès à présent proposer du contenu tels que des articles, des événements, des tutoriels, ... alors n'hésitez pas !
Crédit des images de la plate-forme : Pixabay - Pixabay License | Pexels - Pexels License