Skip to content
Snippets Groups Projects
Commit 58c198f1 authored by Decouvelaere Antonin's avatar Decouvelaere Antonin
Browse files

ajout d'un masque

parent 5835246a
No related branches found
No related tags found
No related merge requests found
......@@ -5,11 +5,15 @@ from RGB_LAB import *
from K_clustering import *
from binary_thresholding import *
from Retour_RGB import *
from masque import remove_isolated_pixels
image_RGB=resizing1("exemple_image.jpg")
image_traitee=Binary_tresholding(K_clustering(RGB_LAB(resizing1("exemple_image.jpg"))))
image_RGB=resizing1("C:\\Users\\antod\\Desktop\\Projet S6\\ia-detection-leucemie\\exemple_image.jpg")
image_traitee=Binary_tresholding(K_clustering(RGB_LAB(resizing1("C:\\Users\\antod\\Desktop\\Projet S6\\ia-detection-leucemie\\exemple_image.jpg"))))
removed_pixel=remove_isolated_pixels(image_traitee,k=7)
cv2.imshow("image de base",image_RGB)
cv2.imshow('Image traitée', image_traitee)
cv2.imshow('Retour aux origines',mask_RGB(image_RGB,image_traitee))
cv2.imshow('Retour aux origines',mask_RGB(image_RGB,removed_pixel))
cv2.imshow('masque',removed_pixel)
cv2.waitKey(0)
cv2.destroyAllWindows()
\ No newline at end of file
import cv2 as cv
import numpy as np
import cv2
def remove_isolated_pixels(img,k=7):
"""k est la taile du motif pour supprimer le bruit avec la focntion otsu"""
blur = cv.GaussianBlur(img,(k,k),0)
ret3,img_th3 = cv.threshold(blur,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU)
return img_th3
def remove_isolated_pixels(src):
kernel = np.ones((3, 3), np.uint8) # Kernel 3x3 pour compter les voisins
neighbor_count = cv2.filter2D(src, ddepth=-1, kernel=kernel) # Comptage des pixels blancs autour de chaque pixel
# Masques pour les pixels isolés
isolated_white = (src == 255) & (neighbor_count <= 255 * 2) # Pixels blancs isolés
isolated_black = (src == 0) & (neighbor_count >= 255 * 7) # Pixels noirs isolés
# Création d'une copie et correction des pixels isolés
result = src.copy()
result[isolated_white] = 0 # Remplace les pixels blancs isolés par du noir
result[isolated_black] = 255 # Remplace les pixels noirs isolés par du blanc
return result
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment