0

I implemented a function, that maps a vector of unique numbers in the range of (-109) - 147 to a new range of 0 - 159 folowing this.

The mapping works fine so far and each all the numbers are transfered to the correct range. I repeated this for a second vector (new range 0 - 119)

The problem I face is that each pair of numbers (one from each vector) represents a position in a 160x120 image and should therefore be unique. Due to a division that needs to be made in the mapping function that returns a float I used the round() to convert to an int (116.341 -> 116). But this leads to the problem that point pairs are not unique anymore as:

Point     ->    new Range   -> round()
--------------------------------------
177x(-99) -> 117.670x3.9608 -> 118x4 !
176x(-99) -> 117.006x3.9608 -> 118x4 !

are correctly mapped to the desired range but are now representing the same point and are not unique anymore. It is important that: every point is being mapped to the new range and that there is no information loss, such as that duplicates get discarded. (Point pairs are holding further color information that must be maintained.)

Is there a way to solve this issue?

Community
  • 1
  • 1
Kevin Katzke
  • 3,581
  • 3
  • 38
  • 47
  • Unique + "_mapping_" + two variables only = Use `std::map` from `#include `. Edit: Oh so you want to keep duplicates but still use round()? – Khalil Khalaf Aug 23 '16 at 15:47
  • 2
    The range [0,159] has 160 integers, so clearly if your vector has more than 160 elements it won't be possible to map its members uniquely to the new range. – Mark Aug 23 '16 at 15:57
  • Not quite clear - do you want new range numbers to be unique as well? That's simply is not possible by obvious reason. – Slava Aug 23 '16 at 15:57
  • What do you actually want to do with the image and its pixels? Maybe there is an easier solution than to map pixels to other pixels. – Dialecticus Aug 23 '16 at 15:58

1 Answers1

1

It is impossible to create one-to-one mapping for different ranges of integers (sets of different powers) due to Dirichlet pigeonhole principle

Note that if reversible mapping would be possible, you might create archiver with infinite compression and squeeze any size file to one or some bytes, then restore it

MBo
  • 77,366
  • 5
  • 53
  • 86