Rewrite `grad_func` and `inpaint_point` to avoid highly indented code
Change the data type from `cnp.int8` to `cnp.int16` to avoid overflow