# Question of Telea Inpaint Source Code

**URL:** <https://forum.opencv.org/t/question-of-telea-inpaint-source-code/20902>\
**Category:** Uncategorized\
**Tags:** imgproc, photo\
**Created:** [April 27, 2025, 9:26am UTC](https://forum.opencv.org/t/question-of-telea-inpaint-source-code/20902 "2025-04-27T09:26:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo1212](https://avatars.discourse-cdn.com/v4/letter/l/3d9bf3/32.png) [@Leo1212](https://forum.opencv.org/u/Leo1212)\
**Post date:** [April 27, 2025, 9:26am UTC](https://forum.opencv.org/t/question-of-telea-inpaint-source-code/20902/1 "2025-04-27T09:26:14Z")

</div>

I’m reading the source code of Telea Inpaint method. The grandiant calculate code makes me confused.  
/modules/photo/src/inpaint.cpp #319

```auto
if (CV_MAT_ELEM(*f,uchar,k,l+1)!=INSIDE) {
    if (CV_MAT_ELEM(*f,uchar,k,l-1)!=INSIDE) {
        gradI.x=(float)((CV_MAT_3COLOR_ELEM(*out,uchar,km,lp+1,color)-CV_MAT_3COLOR_ELEM(*out,uchar,km,lm-1,color)))*2.0f;
    } else {
        gradI.x=(float)((CV_MAT_3COLOR_ELEM(*out,uchar,km,lp+1,color)-CV_MAT_3COLOR_ELEM(*out,uchar,km,lm,color)));
    }
}

```

gradI.x is calculated here. If (k, l+1) and (k, l-1) are not INSIDE (known points), the gradiant is calculated as pixel [(k, l+1) - (k, l-1)]\* 2. But I think it should be [(k, l+1) - (k, l-1)]\* 0.5. Because the code below, calculate the gradiant as (k, l+1) - (k, l) .  
I wonder if this is a bug or some other process strategy I didn’t understand.
