Kevin Katzke
Kevin Katzke

Reputation: 3771

Avoid duplicate values when mapping from one range to another

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?

Upvotes: 0

Views: 224

Answers (1)

MBo
MBo

Reputation: 80325

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

Upvotes: 1

Related Questions