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;
64 typedef typename std::list<entry_t> list_t;
73 ImageCodeMap(std::initializer_list<entry_t> l) : cont_t(l), separator(0) {
97 typename cont_t::const_iterator retrieve(
double d)
const {
99 typename cont_t::const_iterator it = this->begin();
100 typename cont_t::const_iterator rit = it;
102 while (it != this->end()){
114 typename cont_t::iterator retrieve(
double d) {
116 typename cont_t::iterator it = this->begin();
117 typename cont_t::iterator rit = it;
119 while (it != this->end()){
166 lookUp.byteSize = drain::Type::call<drain::sizeGetter>(type);
169 if (type ==
typeid(
unsigned short)){
170 if ((scaling.
scale == 1.0) && (scaling.
offset == 0.0)){
171 double first = this->begin()->first;
172 double last = this->rbegin()->first;
173 if ((first >= 0.0) && (last <= 255.0)){
175 mout.
note(
"short int, but not using 16 bits, coping with 256 entries" );
184 else if (type ==
typeid(
unsigned char)){
188 mout.
note(
"not supported for type " , drain::Type::getTypeChar(type) );
195 const int n = (1 << (lookUp.byteSize*8 - lookUp.bitShift));
196 mout.
debug(
"type=" , drain::Type::getTypeChar(type) ,
", creating " , n ,
" lookup entries" );
198 typename cont_t::const_iterator itLower = this->begin();
200 lookUp.resize(n, itLower);
203 int index, indexLower=0;
206 for (
typename cont_t::const_iterator it=this->begin(); it!=this->end(); ++it){
209 index =
static_cast<int>(scaling.
inv(it->first));
212 mout.
warn(
"underflow threshold " , it->first ,
" mapped to negative index " , index ,
" (before bitShift), skipping " );
216 index = (index >> lookUp.bitShift);
219 mout.
warn(
"overflow: threshold ", it->first,
" mapped to index (", index,
") > max (", (n-1),
"), skipping " );
223 if (indexLower < index){
224 mout.
debug(
"adding index range [", indexLower,
'-', index,
"[ -> (", itLower->first,
") => {", itLower->second,
'}');
227 mout.
note(
"accuracy loss: skipped entry [" , index ,
"] => ", it->first );
231 for (
int i=indexLower; i<index; ++i){
241 if (indexLower < index){
242 mout.
debug() <<
"padding [" << indexLower <<
'-' << index <<
"[ -> \t";
243 mout <<
'[' << itLower->first <<
"] // " << itLower->second << mout.endl;
245 for (
int i=indexLower; i<index; ++i){
Definition ImageCodebook.h:52
ImageCodeMap()
Default constructor.
Definition ImageCodebook.h:69
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:159
drain::LookUp< typename cont_t::const_iterator > lookup_t
LOOK-UP table is an array of pointers to the actual Palette.
Definition ImageCodebook.h:61
ImageCodeMap(const cont_t &map)
Copy constructor //.
Definition ImageCodebook.h:79
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:666
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:489
Look-up tables.
Definition LookUp.h:61
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