Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP-IA-Syntax-Error
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIGEOLAS-CHOURY Paul
TP-IA-Syntax-Error
Commits
398e7538
Commit
398e7538
authored
4 months ago
by
paul_pvc
Browse files
Options
Downloads
Patches
Plain Diff
push GLCM optimisé
parent
6b30b339
No related branches found
No related tags found
1 merge request
!1
Gris
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
TP.py
+23
-6
23 additions, 6 deletions
TP.py
with
23 additions
and
6 deletions
TP.py
+
23
−
6
View file @
398e7538
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment