Skip to content
Snippets Groups Projects
Commit 398e7538 authored by paul_pvc's avatar paul_pvc
Browse files

push GLCM optimisé

parent 6b30b339
No related branches found
No related tags found
1 merge request!1Gris
......@@ -5,6 +5,7 @@ import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from skimage.feature import graycomatrix, graycoprops
from sklearn.naive_bayes import GaussianNB
......@@ -30,10 +31,18 @@ def buildSampleFromPath(path1, path2, size=0):
return S
def computePixelBW_histo(image):
return image.convert("L").histogram()
def computePixelBW_histo(image_gl):
return image_gl.histogram()
def compute_glcm(image):
def compute_glcm_caracteristics(image_gl):
image_arr= np.array(image_gl)
#print(image_arr.shape)
glcm = graycomatrix(image_arr, distances=[5], angles=[0], levels=256,
symmetric=True, normed=True)
return [graycoprops(glcm, 'dissimilarity')[0, 0], graycoprops(glcm, 'correlation')[0, 0], graycoprops(glcm, 'contrast')[0, 0],
graycoprops(glcm, 'energy')[0, 0], graycoprops(glcm, 'homogeneity')[0, 0]]
"""def compute_glcm(image):
img_array = np.array(image)
distance, angle = 5, 0
glcm = np.zeros((256, 256))
......@@ -48,12 +57,19 @@ def compute_glcm(image):
return glcm
def extract_data_glcm(glcm):
contrast, energy, homogeneity = 0, 0, 0
for i in range(glcm.shape[0]):
for j in range(glcm.shape[1]):
contrast += (i - j) ** 2 * glcm[i, j]
energy += glcm[i, j]**2
homogeneity += (glcm[i, j] / (1 + abs(i - j)))
contrast = np.sum([[(i - j) ** 2 * glcm[i, j] for j in range(glcm.shape[1])] for i in range(glcm.shape[0])])
energy = np.sum(glcm ** 2)
homogeneity = np.sum(
[[(glcm[i, j] / (1 + abs(i - j))) for j in range(glcm.shape[1])] for i in range(glcm.shape[0])])
return [contrast, energy, homogeneity]
return [contrast, energy, homogeneity]"""
def computeDict(image_path, path, y_true_value, max_size: tuple):
"""
......@@ -70,14 +86,15 @@ def computeDict(image_path, path, y_true_value, max_size: tuple):
image = image.convert("RGB")
resized = resizeImage(image, *max_size) # On ne stocke pas resized image, on calcule tout avant de l'oublier
image_gl = resized.convert("L")
#print(computePixelBW_histo(resized))
return {"name_path": full_path,
#"resized_image": resized,
"X_histo": computeHisto(resized),
"X_pixelbw": computePixelBW_histo(resized),
"X_glcm_data": extract_data_glcm(compute_glcm(resized)),
#"X_glcm_data": extract_data_glcm(compute_glcm(resized)),
"X_glcm_data": compute_glcm_caracteristics(image_gl),
"y_true_class": y_true_value,
"y_predicted_class": None}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment