Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
2f8b7254
Commit
2f8b7254
authored
Feb 15, 2011
by
Sebastian Eichelbaum
Browse files
[CHANGE] - improced histogram a little bit as well as histogram euqalizer.
parent
e9828d66
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
21 deletions
+29
-21
src/dataHandler/datastructures/WValueSetHistogram.cpp
src/dataHandler/datastructures/WValueSetHistogram.cpp
+4
-2
src/dataHandler/datastructures/WValueSetHistogram.h
src/dataHandler/datastructures/WValueSetHistogram.h
+2
-2
src/modules/histogramEqualization/WMHistogramEqualization.cpp
...modules/histogramEqualization/WMHistogramEqualization.cpp
+23
-17
No files found.
src/dataHandler/datastructures/WValueSetHistogram.cpp
View file @
2f8b7254
...
...
@@ -254,10 +254,12 @@ std::ostream& operator<<( std::ostream& out, const WValueSetHistogram& h )
{
std
::
pair
<
double
,
double
>
interval
=
h
.
getIntervalForIndex
(
i
);
// NOTE: the notation for open intervals is [a,b) or alternatively [a,b[.
out
<<
i
<<
" = ["
<<
interval
.
first
<<
", "
<<
interval
.
second
<<
") = "
<<
h
[
i
]
<<
std
::
endl
;
//out << i << " = [" << interval.first << ", " << interval.second << ") = " << h[ i ] << std::endl;
out
<<
interval
.
first
<<
" "
<<
interval
.
second
<<
" "
<<
std
::
min
(
h
[
i
],
size_t
(
3000
)
)
<<
std
::
endl
;
}
// the last interval is handled special
out
<<
h
.
size
()
-
1
<<
" = ["
<<
h
.
getIntervalForIndex
(
h
.
size
()
-
1
).
first
<<
", inf) = "
<<
h
[
h
.
size
()
-
1
]
<<
std
::
endl
;
//out << h.size() - 1 << " = [" << h.getIntervalForIndex( h.size() - 1 ).first << ", inf) = " << h[ h.size() - 1 ] << std::endl;
out
<<
h
.
getIntervalForIndex
(
h
.
size
()
-
1
).
first
<<
" inf "
<<
std
::
min
(
h
[
h
.
size
()
-
1
],
size_t
(
3000
)
)
<<
std
::
endl
;
return
out
;
}
...
...
src/dataHandler/datastructures/WValueSetHistogram.h
View file @
2f8b7254
...
...
@@ -270,12 +270,12 @@ inline size_t WValueSetHistogram::getIndexForValue( double value ) const
// the position on the scala
double
pos
=
(
value
-
m_minimum
)
/
static_cast
<
double
>
(
m_mappedBucketSize
);
// the index is the floor( position )
size_t
idx
=
static_cast
<
size_t
>
(
pos
);
size_t
idx
=
static_cast
<
size_t
>
(
std
::
floor
(
pos
)
);
// is the index larger than the size?
bool
inU
=
(
idx
<
m_nMappedBuckets
);
// is the index smaller than the size?
bool
inL
=
(
pos
>
0.0
);
bool
inL
=
(
pos
>
=
0.0
);
// the trick done here is to clamp value into [m_minimum,m_maximum] without using if statements. The C++ Standard says that booleans are
// always 1 if true.
...
...
src/modules/histogramEqualization/WMHistogramEqualization.cpp
View file @
2f8b7254
...
...
@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <vector>
#include <fstream>
#include <string>
#include "../../kernel/WKernel.h"
...
...
@@ -211,16 +212,20 @@ void WMHistogramEqualization::moduleMain()
curI
++
;
}
debugLog
()
<<
"Clamped "
<<
perc
<<
"% resulting in new interval ["
<<
lower
<<
", "
<<
upper
<<
")."
;
debugLog
()
<<
"Clamped "
<<
perc
<<
"%
of ["
<<
hist
->
getMinimum
()
<<
", "
<<
hist
->
getMaximum
()
<<
"]"
<<
"
resulting in new interval ["
<<
lower
<<
", "
<<
upper
<<
")."
;
// with this new interval, extract a new histogram and use it for equalization
hist
=
boost
::
shared_ptr
<
const
WValueSetHistogram
>
(
new
WValueSetHistogram
(
valueSet
,
lower
,
upper
,
cdfHistRes
)
);
}
// the new data
std
::
vector
<
unsigned
char
>
newData
;
std
::
vector
<
double
>
newData
;
newData
.
resize
(
hist
->
getTotalElementCount
(),
0
);
// these values are needed to rescale the data to the original interval
double
valueMin
=
hist
->
getMinimum
();
double
valueScaler
=
hist
->
getMaximum
()
-
valueMin
;
// equalize?
++*
progress
;
if
(
m_equalize
->
get
(
true
)
)
...
...
@@ -232,24 +237,23 @@ void WMHistogramEqualization::moduleMain()
// go through each CDF item and fill it, which is the sum of all previous items in hist
size_t
accum
=
0
;
double
cdfMin
=
(
*
hist
)[
0
];
double
cdfScaler
=
static_cast
<
double
>
(
valueSet
->
rawSize
()
)
-
cdfMin
;
for
(
size_t
i
=
0
;
i
<
hist
->
size
();
++
i
)
{
// the CDF at i is the summed up histogram from 0 to i
// we additionally require the histogram to be normalized so divide by the total count
accum
+=
(
*
hist
)[
i
];
cdf
[
i
]
=
accum
;
cdf
[
i
]
=
accum
-
cdfMin
;
}
// finally, build the new dataset
debugLog
()
<<
"Calculating equalized value-set"
;
double
cdfMin
=
cdf
[
0
];
for
(
size_t
vi
=
0
;
vi
<
valueSet
->
rawSize
();
++
vi
)
{
double
cdfVI
=
cdf
[
hist
->
getIndexForValue
(
valueSet
->
getScalarDouble
(
vi
)
)
];
newData
[
vi
]
=
static_cast
<
unsigned
char
>
(
255.0
*
(
cdfVI
-
cdfMin
)
/
(
static_cast
<
double
>
(
valueSet
->
rawSize
()
)
-
cdfMin
)
);
size_t
idx
=
hist
->
getIndexForValue
(
valueSet
->
getScalarDouble
(
vi
)
);
double
cdfVI
=
cdf
[
idx
];
newData
[
vi
]
=
valueMin
+
(
valueScaler
*
cdfVI
/
cdfScaler
);
}
}
else
...
...
@@ -260,7 +264,8 @@ void WMHistogramEqualization::moduleMain()
for
(
size_t
vi
=
0
;
vi
<
valueSet
->
rawSize
();
++
vi
)
{
size_t
idx
=
hist
->
getIndexForValue
(
valueSet
->
getScalarDouble
(
vi
)
);
newData
[
vi
]
=
static_cast
<
unsigned
char
>
(
static_cast
<
double
>
(
idx
)
/
static_cast
<
double
>
(
maxI
)
*
255.0
);
double
idxScaled
=
(
static_cast
<
double
>
(
idx
)
/
static_cast
<
double
>
(
maxI
)
);
newData
[
vi
]
=
valueMin
+
(
valueScaler
*
idxScaled
);
}
}
++*
progress
;
...
...
@@ -269,14 +274,15 @@ void WMHistogramEqualization::moduleMain()
debugLog
()
<<
"Updating output"
;
// construct
m_output
->
updateData
(
boost
::
shared_ptr
<
WDataSetScalar
>
(
boost
::
shared_ptr
<
WDataSetScalar
>
d
=
boost
::
shared_ptr
<
WDataSetScalar
>
(
new
WDataSetScalar
(
boost
::
shared_ptr
<
WValueSetBase
>
(
new
WValueSet
<
unsigned
char
>
(
0
,
new
WValueSet
<
double
>
(
0
,
1
,
boost
::
shared_ptr
<
std
::
vector
<
unsigned
char
>
>
(
new
std
::
vector
<
unsigned
char
>
(
newData
)
),
W_DT_UNSIGNED_CHAR
)
),
dataSet
->
getGrid
()
)
)
);
boost
::
shared_ptr
<
std
::
vector
<
double
>
>
(
new
std
::
vector
<
double
>
(
newData
)
),
W_DT_DOUBLE
)
),
dataSet
->
getGrid
()
)
)
;
m_output
->
updateData
(
d
);
debugLog
()
<<
"Done"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment