31 #ifndef DRAIN_CODEBOOK
32 #define DRAIN_CODEBOOK
35 #include <drain/Log.h>
40 #include "drain/util/ValueScaling.h"
41 #include "drain/util/LookUp.h"
56 typedef std::map<double,T> cont_t;
57 typedef typename cont_t::key_type key_t;
58 typedef typename cont_t::value_type entry_t;
62 typedef typename std::list<entry_t> list_t;
71 ImageCodeMap(std::initializer_list<entry_t> l) : cont_t(l), separator(0) {
102 lookUp.byteSize = drain::Type::call<drain::sizeGetter>(type);
105 if (type ==
typeid(
unsigned short)){
106 if ((scaling.
scale == 1.0) && (scaling.
offset == 0.0)){
107 double first = this->begin()->first;
108 double last = this->rbegin()->first;
109 if ((first >= 0.0) && (last <= 255.0)){
111 mout.
note(
"short int, but not using 16 bits, coping with 256 entries" );
120 else if (type ==
typeid(
unsigned char)){
124 mout.
note(
"not supported for type " , drain::Type::getTypeChar(type) );
131 const int n = (1 << (lookUp.byteSize*8 - lookUp.bitShift));
132 mout.
debug(
"type=" , drain::Type::getTypeChar(type) ,
", creating " , n ,
" lookup entries" );
134 typename cont_t::const_iterator itLower = this->begin();
136 lookUp.resize(n, itLower);
139 int index, indexLower=0;
142 for (
typename cont_t::const_iterator it=this->begin(); it!=this->end(); ++it){
145 index =
static_cast<int>(scaling.
inv(it->first));
148 mout.
warn(
"underflow threshold " , it->first ,
" mapped to negative index " , index ,
" (before bitShift), skipping " );
152 index = (index >> lookUp.bitShift);
155 mout.
warn(
"overflow: threshold ", it->first,
" mapped to index (", index,
") > max (", (n-1),
"), skipping " );
159 if (indexLower < index){
160 mout.
debug(
"adding index range [", indexLower,
'-', index,
"[ -> (", itLower->first,
") => {", itLower->second,
'}');
163 mout.
note(
"accuracy loss: skipped entry [" , index ,
"] => ", it->first );
167 for (
int i=indexLower; i<index; ++i){
177 if (indexLower < index){
178 mout.
debug() <<
"padding [" << indexLower <<
'-' << index <<
"[ -> \t";
179 mout <<
'[' << itLower->first <<
"] // " << itLower->second << mout.endl;
181 for (
int i=indexLower; i<index; ++i){
189 typename cont_t::const_iterator retrieve(
double d)
const {
191 typename cont_t::const_iterator it = this->begin();
192 typename cont_t::const_iterator rit = it;
194 while (it != this->end()){
206 typename cont_t::iterator retrieve(
double d) {
208 typename cont_t::iterator it = this->begin();
209 typename cont_t::iterator rit = it;
211 while (it != this->end()){
Definition: ImageCodebook.h:52
ImageCodeMap()
Default constructor.
Definition: ImageCodebook.h:67
lookup_t & createLookUp(const std::type_info &type, const ValueScaling &scaling) const
Creates a vector of 256 or 65535 entries for fast retrieval.
Definition: ImageCodebook.h:95
drain::LookUp< typename cont_t::const_iterator > lookup_t
LOOK-UP table.
Definition: ImageCodebook.h:78
ImageCodeMap(const cont_t &map)
Copy constructor //.
Definition: ImageCodebook.h:77
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:485
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Linear scaling and physical range for image intensities.
Definition: ValueScaling.h:64
double & scale
Multiplicative coefficient \i a in: y = ax + b.
Definition: ValueScaling.h:68
double & offset
Additive coefficient \i b in: y = ax + b.
Definition: ValueScaling.h:71
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition: ValueScaling.h:301
Definition: DataSelector.cpp:1277