If you are enlarging the image, you should prefer to use INTER_LINEAR or INTER_CUBIC interpolation. If you are shrinking the image, you should prefer to use INTER_AREA interpolation.
Cubic interpolation is computationally more complex, and hence slower than linear interpolation. However, the quality of the resulting image will be higher.
为了克服这个问题,您应该找出可以进行插值的给定图像的新尺寸。并在目标图像上复制插值采样图像,如:
- # create target image and copy sample image into it
- (wt, ht) = imgSize # target image size
- (h, w) = img.shape # given image size
- fx = w / wt
- fy = h / ht
- f = max(fx, fy)
- newSize = (max(min(wt, int(w / f)), 1),
- max(min(ht, int(h / f)), 1)) # scale according to f (result at least 1 and at most wt or ht)
- img = cv2.resize(img, newSize, interpolation=cv2.INTER_CUBIC) #INTER_CUBIC interpolation
- target = np.ones([ht, wt]) * 255 # shape=(64,800)
- target[0:newSize[1], 0:newSize[0]] = img
有关每个插值的结果,cv2 resize interpolation methods - Chadrick's Blog
一
openCV中一些可能的插值是: