【问题标题】:Python OpenCV image interpolation inaccuracyPython OpenCV 图像插值不准确
【发布时间】:2015-01-27 14:39:37
【问题描述】:

我熟悉通过 Python 接口使用 OpenCV,但是在使用图像插值工具解决需要很高准确性的一些非标准问题时,我注意到结果中有一些意外的不准确性。下面的代码说明了我的问题。有任何想法吗?我只是想在设计精度之外使用插值器吗?

import numpy as np
import cv2
import matplotlib.pyplot as plt

# Source gradient image from 0 to 255
src = np.atleast_2d(np.linspace(0,255,10));

# Set up to interpolate from first pixel value to last pixel value
map_x_32 = np.linspace(0,9,101)
map_x_32 = np.atleast_2d(map_x_32).astype('float32')
map_y_32 = map_x_32*0

# Interpolate using OpenCV
output = cv2.remap(src, map_x_32, map_y_32, cv2.INTER_LINEAR)

# Truth
output_truth = np.atleast_2d(np.linspace(0,255,101));

interp_error = output - output_truth

plt.plot(interp_error[0])

【问题讨论】:

    标签: python image opencv interpolation


    【解决方案1】:

    我也遇到过同样的错误。 scipy.ndimage.map_coordinates 更准确,但在我的情况下也慢了 5 倍。

    在这种情况下,您可以将其用作:

    # Interpolate using Scipy
    xy = np.vstack((map_y_32[np.newaxis,:,:], map_x_32[np.newaxis,:,:]))
    output_scipy = scipy.ndimage.map_coordinates(src, xy, order=1)
    

    【讨论】:

      猜你喜欢
      • 2017-03-31
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多