0
点赞
收藏
分享

微信扫一扫

测试scipy.interpolate.interp2d对于低分辨率图像插值处理结果

 

 

§01 interp2d函数


1.1 函数功能

  根据 scipy.interpolate.interp2d 中对于interp2d的用法进行了介绍。

class scipy.interpolate.interp2d(x, y, z, kind='linear', copy=True, bounds_error=False, fill_value=nan)

1.1.1 函数参数

  • x, y : array_like
      Arrays defining the data point coordinates.

  If the points lie on a regular grid, x can specify the column coordinates and y the row coordinates, for example:

  • z : array_like
      The values of the function to interpolate at the data points. If z is a multi-dimensional array, it is flattened before use. The length of a flattened z array is either len(x)*len(y) if x and y specify the column and row coordinates or len(z) == len(x) == len(y) if x and y specify coordinates for each point.

  • kind : {‘linear’, ‘cubic’, ‘quintic’}, optional
      The kind of spline interpolation to use. Default is ‘linear’.

  • copy : bool, optional
      If True, the class makes internal copies of x, y and z. If False, references may be used. The default is to copy.

  • bounds_error : bool, optional
      If True, when interpolated values are requested outside of the domain of the input data (x,y), a ValueError is raised. If False, then fill_value is used.

  • fill_value : number, optional
      If provided, the value to use for points outside of the interpolation domain. If omitted (None), values outside the domain are extrapolated.

1.1.2 函数返回

  • values_x : ndarray, shape xi.shape[:-1] + values.shape[ndim:]
      Interpolated values at input coordinates.

1.2 举例

from scipy import interpolate
x = np.arange(-5.01, 5.01, 0.25)
y = np.arange(-5.01, 5.01, 0.25)
xx, yy = np.meshgrid(x, y)
z = np.sin(xx**2+yy**2)
f = interpolate.interp2d(x, y, z, kind='cubic')

▲ 图1.2.1 函数取值

▲ 图1.2.1 函数取值

▲ 图1.2.2 插值之后的图像

▲ 图1.2.2 插值之后的图像

xnew = np.arange(-5.01, 5.01, 1e-2)
ynew = np.arange(-5.01, 5.01, 1e-2)
znew = f(xnew, ynew)
plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
plt.show()

▲ 图1.2.3 对于x轴方面的插值结果

▲ 图1.2.3 对于x轴方面的插值结果

 

§02 像插值


2.1 插值图像

  利用在 利用圆圈轮廓面积求取圆环半径:cv2.findContours, contourArea 抑菌圈金属模板扫描图片,通过 cv2.resize之后形成64×64的分辨率的图像。

2.1.1 原始图像

import sys,os,math,time
import matplotlib.pyplot as plt
from numpy import *
import cv2
from scipy                  import interpolate

filename = '/home/aistudio/work/Scanner/ScanDiagBlock/img258.jpg'

img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray32 = cv2.resize(gray, (64,64))

plt.figure(figsize=(10,10))
plt.imshow(gray32)
plt.savefig('/home/aistudio/stdout.jpg')

▲ 图2.1.1 设置成分辨率为64×64图片

▲ 图2.1.1 设置成分辨率为64×64图片

2.1.2 插值图像

x = arange(64)
y = arange(64)
f = interpolate.interp2d(x,y,gray32, kind='cubic')

xx = arange(0, 64, 0.1)
yy = arange(0, 64, 0.1)
zz = f(xx, yy)
plt.figure(figsize=(10,10))
plt.imshow(zz)
plt.savefig('/home/aistudio/stdout.jpg')

(1)立方插值

▲ 图2.1.2 插值后的图像

▲ 图2.1.2 插值后的图像

(2)线性插值

▲ 图2.1.3 线性插值

▲ 图2.1.3 线性插值

(3)四次方插值

▲ 图2.1.4 四次方插值

▲ 图2.1.4 四次方插值

 

值总结 ※


  用scipy.interpolate.interp2d可以对图像进行插值,获得图像在各个方向的渐进过度过程。这可以为后面在一些特征点进行超像素处理中提供更加精确光滑的数据处理过程。


■ 相关文献链接:

  • scipy.interpolate.interp2d
  • 利用圆圈轮廓面积求取圆环半径:cv2.findContours, contourArea

● 相关图表链接:

#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# TEST3.PY                     -- by Dr. ZhuoQing 2022-01-27
#
# Note:
#============================================================
from headm import *                 # =
import cv2
from scipy                  import interpolate
filename = '/home/aistudio/work/Scanner/ScanDiagBlock/img258.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray32 = cv2.resize(gray, (64,64))
plt.figure(figsize=(10,10))
plt.imshow(gray32)
plt.savefig('/home/aistudio/stdout.jpg')
#------------------------------------------------------------
x = arange(64)
y = arange(64)
f = interpolate.interp2d(x,y,gray32, kind='quintic')
 #------------------------------------------------------------
xx = arange(0, 64, 0.1)
yy = arange(0, 64, 0.1)
zz = f(xx, yy)
plt.figure(figsize=(10,10))
plt.imshow(zz)
plt.savefig('/home/aistudio/stdout.jpg')
#------------------------------------------------------------
#        END OF FILE : TEST3.PY
#============================================================
举报

相关推荐

0 条评论