Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ImageINSA_Tanguy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tanguy.Raufflet
ImageINSA_Tanguy
Commits
ec2bf90f
Commit
ec2bf90f
authored
6 years ago
by
ariotte
Browse files
Options
Downloads
Patches
Plain Diff
fixed LloydMax algorithm quantization
parent
c281fe81
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/Algorithms/Pyramid.cpp
+1
-1
1 addition, 1 deletion
app/Algorithms/Pyramid.cpp
app/Operations/Quantification.cpp
+36
-39
36 additions, 39 deletions
app/Operations/Quantification.cpp
with
37 additions
and
40 deletions
app/Algorithms/Pyramid.cpp
+
1
−
1
View file @
ec2bf90f
...
...
@@ -66,7 +66,7 @@ Pyramid::Filters::Filters()
num_filters
=
5
;
filters
=
all_filters
;
/*
Old fix might work on windows if everything else fail
/*Old fix might work on windows if everything else fail
num_filters=(int)sizeof(tp6_filter_file_data)/sizeof(Filtre);
filters = reinterpret_cast<const Filtre*>(tp6_filter_file_data);*/
}
...
...
This diff is collapsed.
Click to expand it.
app/Operations/Quantification.cpp
+
36
−
39
View file @
ec2bf90f
...
...
@@ -189,56 +189,53 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im
Quantification
Quantification
::
lloydMaxQuant
(
int
size
,
const
Image
*
image
,
unsigned
int
c
)
{
// Quantification quant(size);
// for(int i = 0; i < size - 1; ++i) {
// quant._threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5);
// }
// if(size > 0) {
// quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 );
// quant._values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant._threshold[size - 2]) / 2. + 0.5 );
// }
// for(int i = 1; i < size - 1; ++i) {
// quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 );
// }
// return quant;
Histogram
histogram
=
image
->
getHistogram
(
c
);
int
som_lum
=
0
;
int
nb_points
=
0
;
int
cpt
=
12
;
int
cpt
=
50
;
// Securite pour limiter le nombre de boucle si on ne converge pas
int
diff
[
size
-
1
];
int
diff_mean
=
100
;
// initialisation : repartion lineaire des niveaux de quantification
Quantification
quant
=
linearQuant
(
size
);
while
(
cpt
>
0
){
// calcul des nouveaux seuils de quantification
for
(
int
i
=
0
;
i
<
size
-
2
;
i
++
){
quant
.
_threshold
[
i
]
=
(
quant
.
_values
[
i
]
+
quant
.
_values
[
i
+
1
])
/
2
;
}
//for (parcours du tableau de seuils)
while
(
cpt
>
0
&&
diff_mean
>=
1
){
// calcul des nouveaux niveaux de quantification
//calcul pdf
for
(
int
j
=
0
;
j
<
size
-
2
;
j
++
){
for
(
int
i
=
((
quant
.
_threshold
)[
j
]);
i
<=
((
quant
.
_threshold
)[
j
+
1
]);
i
++
){
som_lum
+=
histogram
[
i
]
*
i
;
for
(
int
j
=
1
;
j
<
size
-
1
;
j
++
){
som_lum
=
0
;
nb_points
=
0
;
//Calcul des baricentres entre deux seuils
for
(
int
i
=
((
quant
.
_threshold
)[
j
-
1
]);
i
<=
((
quant
.
_threshold
)[
j
]);
i
++
){
som_lum
+=
histogram
[
i
]
*
i
;
nb_points
+=
histogram
[
i
];
}
//Evite les divisions par 0. On estime que s'il n'y a pas d'élements le baricentre est le milieu du segment
if
(
nb_points
>
0
)
quant
.
_values
[
j
]
=
(
int
)
(
som_lum
/
nb_points
);
else
quant
.
_values
[
j
]
=
(
quant
.
_threshold
[
j
]
+
quant
.
_threshold
[
j
+
1
])
/
2
;
quant
.
_values
[
j
]
=
(
int
)
(
som_lum
/
nb_points
);
//weird equation :
// quant._values[j]= (int) quant._values[j]*(som_lum/nb_points) / (som_lum/nb_points);
}
//for (parcours du tableau de valeurs)
}
// calcul des nouveaux seuils de quantification
for
(
int
i
=
0
;
i
<
size
-
1
;
i
++
){
diff
[
i
]
=
quant
.
_threshold
[
i
];
//centrage des seuils de décision entre chaque niveaux de quantification
quant
.
_threshold
[
i
]
=
(
quant
.
_values
[
i
]
+
quant
.
_values
[
i
+
1
])
/
2
;
diff
[
i
]
=
abs
(
diff
[
i
]
-
quant
.
_threshold
[
i
]);
}
//calcul de la condition d'arret (moyenne des écarts < 1 )
for
(
int
i
=
0
;
i
<
size
-
1
;
i
++
){
diff_mean
+=
diff
[
i
];
}
diff_mean
=
diff_mean
/
(
size
-
1
);
cpt
--
;
}
//while
}
return
quant
;
}
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