# Synopse

Return the value of the closest pixel (2D) or voxel (3D)

• result = iainterpolclosest(im, pts)
• im: 1D, 2D or 3D image to be interpolated
• pts: array DxN with the points to interpolate (one in each column)
• result: array of the interpolated values

```01. def iainterpolclosest(f, pts):
02.     # f - one, two or three dimention array
03.     # pts - array of points to interpolate
04.     import numpy as np
05.     ptsi = np.rint(pts).astype(int)
06.     ptsi[ptsi<0] = 0
07.
08.     # make sure ptsi dimention is >= 2
09.     if ptsi.ndim==1:
10.         ptsi.shape = (1, ptsi.size)
11.     for i in range(0, f.ndim):
12.         ptsi[i] = np.minimum(ptsi[i], f.shape[i]-1)
13.     return f[list(ptsi)]```

# Example

```01. from iainterpolclosest import iainterpolclosest
02. import numpy as np
03. im = np.array([[ 0,  1, 2, 3, 4, 5,  6,  7],
04.                [10, 11,12,13,14,15, 16, 17]])
05. pts = np.array([[0.1, 0.5, 1.4, 1.5, 1.8, -10, 100],
06.                 [0.1, 0.8, 1.4, 1.6, 6.3, 6.7, 6.7]])
07.
08. print "im=\n", im
09. print "pts=\n", pts
10. print "values=\n", iainterpolclosest(im, pts)```
```im=
[[ 0  1  2  3  4  5  6  7]
[10 11 12 13 14 15 16 17]]
pts=
[[   0.1    0.5    1.4    1.5    1.8  -10.   100. ]
[   0.1    0.8    1.4    1.6    6.3    6.7    6.7]]
values=
[ 0  1 11 12 16  7 17]
```