I'm trying to interpolate up an image with cv2.resize(), while keeping the integer position pixel in new image same as the original image. So I wrote this code to test:
import cv2, scipy
import scipy.misc
import numpy as np
im = cv2.imread('img')
print(im[:,:,0].shape)
print(im[:,:,0])
im = cv2.resize(im, None, fx=2, fy=2, interpolation=cv2.INTER_LANCZOS4)
print(im[::2,::2,0].shape)
print(im[::2,::2,0])
Output:
(128, 128)
[[79 62 64 ... 81 81 79]
[73 59 57 ... 79 81 79]
[69 51 51 ... 90 88 87]
...
[40 48 43 ... 79 84 88]
[45 46 44 ... 84 84 83]
[48 46 44 ... 80 80 83]]
(128, 128)
[[82 66 63 ... 82 81 80]
[76 64 57 ... 80 79 79]
[71 57 50 ... 90 85 85]
...
[38 46 45 ... 77 84 87]
[43 46 45 ... 83 84 84]
[48 47 44 ... 81 81 82]]
The above code interpolated the image 2x and ideally the two output should be the same, since im[::2,::2,0] should be the pixel before interpolation.
Is there something wrong in the code or anyway to do it properly?