# Question In remap source code,it is wrong here?

**URL:** <https://forum.opencv.org/t/question-in-remap-source-code-it-is-wrong-here/9628>\
**Category:** C++\
**Tags:** imgproc\
**Created:** [July 26, 2022, 2:32am UTC](https://forum.opencv.org/t/question-in-remap-source-code-it-is-wrong-here/9628 "2022-07-26T02:32:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumby](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jumby](https://forum.opencv.org/u/jumby)\
**Post date:** [July 26, 2022, 2:32am UTC](https://forum.opencv.org/t/question-in-remap-source-code-it-is-wrong-here/9628/1 "2022-07-26T02:32:13Z")

</div>

in source code ,I find the table in this way:it means value \< 16 ,then it is 1 or 0

```auto
0.1X32=3.2
0.9X32=28.8

```

I wonder it should be inverse:value \> 15 ,then it is 1 or 0

```auto

//init here
INTER_TAB_SIZE = 32;//32 is the scale size
NNDeltaTab_i[i*INTER_TAB_SIZE+j][0] = j < INTER_TAB_SIZE/2;
NNDeltaTab_i[i*INTER_TAB_SIZE+j][1] = i < INTER_TAB_SIZE/2;

//used here
int a = sA[x1] & (INTER_TAB_SIZE2-1);
XY[x1*2] = sXY[x1*2] + NNDeltaTab_i[a][0];
XY[x1*2+1] = sXY[x1*2+1] + NNDeltaTab_i[a][1];

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 26, 2022, 12:03pm UTC](https://forum.opencv.org/t/question-in-remap-source-code-it-is-wrong-here/9628/2 "2022-07-26T12:03:51Z")

</div>

can you devise an “experiment” using `remap()` and suitable input data, that would show whether the code is correct or wrong?

when in doubt, you should trust that code more than your own understanding. it has received plenty of consideration by people that know what they’re doing.

---

<div class="post-metadata">

**Author:** ![jumby](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@jumby](https://forum.opencv.org/u/jumby)\
**Post date:** [July 27, 2022, 1:33am UTC](https://forum.opencv.org/t/question-in-remap-source-code-it-is-wrong-here/9628/3 "2022-07-27T01:33:10Z")

</div>

nearest remap is hard to find cause there is only small diffs.I have done the experiment before i post it here,it is all the same pixel-wise,but when i find it in source code ,I find something wrong.  
here is my experiment ,opencv official remap and custom result:  
m\_remap\_x\_16\_c2,//CV\_16SC2 x y indice  
m\_remap\_y\_16\_c1);//CV\_16UC1 strip indice with x is in lower 5 bits

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/b2497e0c43bc1728f1ee4f5c22722c4f401ff5fc.png)  
and I have ensure it that there is no diff in outputs

here i get the fusion mapxy for nearest remap,why there is \<16 not \>15 when it plus 1.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/e/e0495726d0ec5164fc6b65968d7987f1ac470809.png)
