Logo elodees  elodees

Une IA bien-veillante pour un monde meilleur













Seuls les caractères alphabétiques accentués ou non ainsi que l'espace sont acceptés

Logo IA




Seuillage d'images





Pas encore de compte ?

Inscrivez-vous pour accéder à tous les contenus


Testé sous Anaconda et Python 3.7

import cv2
from matplotlib import pyplot as plt
 
def showimage(myimage, figsize=[10,10]):
    if (myimage.ndim>2):  #This only applies to RGB or RGBA images (e.g. not to Black and White images)
        myimage = myimage[:,:,::-1] #OpenCV follows BGR order, while matplotlib likely follows RGB order
 
    fig, ax = plt.subplots(figsize=figsize)
    ax.imshow(myimage, cmap = 'gray', interpolation = 'bicubic')
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
    plt.show()
 
img_originale = cv2.imread('inputCoins.jpg', 1)
showimage(img_originale)
 
img_gray = cv2.imread('inputCoins.jpg', 0)
showimage(img_gray)
 
(retVal, newImg) = cv2.threshold(img_gray, 130, 255, cv2.THRESH_BINARY)
showimage(newImg)
 
newImg = cv2.adaptiveThreshold(img_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 15)
showimage(newImg)
 


Image originale

Image gratuite et libre de droits fournie par pexel.com

Nuances de gris

Image gratuite et libre de droits fournie par pexel.com

Seuillage Simple

Image gratuite et libre de droits fournie par pexel.com

Seuillage adaptatif

Image gratuite et libre de droits fournie par pexel.com


Testé sous Anaconda et Python 3.7

# Python program to illustrate
# Otsu thresholding type on an image
 
# organizing imports
import cv2
from matplotlib import pyplot as plt
 
def showimage(myimage, figsize=[10,10]):
    if (myimage.ndim>2):  #This only applies to RGB or RGBA images (e.g. not to Black and White images)
        myimage = myimage[:,:,::-1] #OpenCV follows BGR order, while matplotlib likely follows RGB order
 
    fig, ax = plt.subplots(figsize=figsize)
    ax.imshow(myimage, cmap = 'gray', interpolation = 'bicubic')
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
    plt.show()
 
# path to input image is specified and
# image is loaded with imread command
image_originale = cv2.imread('inputCoins.jpg')
showimage(image_originale)
 
# 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)
showimage(img)
 
# applying Otsu thresholding
# as an extra flag in binary 
# thresholding     
ret, thresh1 = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
 
# the window showing output image         
# with the corresponding thresholding         
# techniques applied to the input image    
showimage(thresh1)
 


Image originale

Image gratuite et libre de droits fournie par pexel.com

Nuances de gris

Image gratuite et libre de droits fournie par pexel.com

Seuillage otsu

Image gratuite et libre de droits fournie par pexel.com


Testé sous Anaconda et Python 3.7

# Python program to illustrate 
# adaptive thresholding type on an image
 
# organizing imports 
import cv2 
from matplotlib import pyplot as plt
 
def showimage(myimage, figsize=[10,10]):
    if (myimage.ndim>2):  #This only applies to RGB or RGBA images (e.g. not to Black and White images)
        myimage = myimage[:,:,::-1] #OpenCV follows BGR order, while matplotlib likely follows RGB order
 
    fig, ax = plt.subplots(figsize=figsize)
    ax.imshow(myimage, cmap = 'gray', interpolation = 'bicubic')
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
    plt.show()
 
# path to input image is specified and  
# image is loaded with imread command 
image_originale = cv2.imread('inputCoins.jpg')
showimage(image_originale)
 
# 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)
 
# applying different thresholding 
# techniques on the input image
thresh1 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, 199, 5)
 
thresh2 = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 199, 5)
 
# the window showing output images
# with the corresponding thresholding 
# techniques applied to the input image
showimage(thresh1)
showimage(thresh2)
 


Image originale

Image gratuite et libre de droits fournie par pexel.com

Nuances de gris

Image gratuite et libre de droits fournie par pexel.com

Seuillage adaptative mean

Image gratuite et libre de droits fournie par pexel.com

Seuillage adaptative gaussian

Image gratuite et libre de droits fournie par pexel.com


Testé sous Anaconda et Python 3.7

# Python program to illustrate
# Otsu thresholding type on an image
 
# organizing imports
import cv2
from matplotlib import pyplot as plt
 
def showimage(myimage, figsize=[10,10]):
    if (myimage.ndim>2):  #This only applies to RGB or RGBA images (e.g. not to Black and White images)
        myimage = myimage[:,:,::-1] #OpenCV follows BGR order, while matplotlib likely follows RGB order
 
    fig, ax = plt.subplots(figsize=figsize)
    ax.imshow(myimage, cmap = 'gray', interpolation = 'bicubic')
    plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
    plt.show()
 
# path to input image is specified and
# image is loaded with imread command
image_originale = cv2.imread('inputCoins.jpg')
showimage(image_originale)
 
# 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)
showimage(img)
 
# 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    
showimage(thresh1)
 
# 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    
showimage(thresh1)
 
# 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    
showimage(thresh1)
 
# 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    
showimage(thresh1)
 


Image originale

Image gratuite et libre de droits fournie par pexel.com

Nuances de gris

Image gratuite et libre de droits fournie par pexel.com

Seuillage Tronqué - Seuil = 50

Image gratuite et libre de droits fournie par pexel.com

Seuillage Tronqué - Seuil = 100

Image gratuite et libre de droits fournie par pexel.com

Seuillage Tronqué - Seuil = 150

Image gratuite et libre de droits fournie par pexel.com

Seuillage Tronqué - Seuil = 200

Image gratuite et libre de droits fournie par pexel.com












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