赞
踩
【时间】2019.09.04 【题目】skimage库的transform.SimilarityTransform()用法 一、SimilarityTransform(图像变换的一种:相似变换) 相似变换:等距变换+均匀尺度缩放,所谓等距变换就是平移+旋转变换。
变换矩阵:
变换效应:角度、平行性和垂直性不发生变换。
二、transform.SimilarityTransform()用法
参考:help(tf.SimilarityTransform)
输入参数:
- matrix : (3, 3) array, optional , Homogeneous transformation matrix.
可选,即上面所说的(3,3)齐次变换矩阵,具体看下面说明。
- scale : float, optional(缩放因子,即s)
- rotation : float, optional Rotation angle in counter-clockwise direction as radians.
(旋转角度θ,逆时针,以弧度表示角度)
- translation : (tx, ty) as array, list or tuple, optional ,x, y translation parameters.
平移参数(tx, ty)
返回:
一个 skimage.transform._geometric.SimilarityTransform object
(3,3)齐次变换矩阵: [[a0 b0 a1] [b0 a0 b1] [0 0 1]] 对比变换矩阵,可知:a0=s * cos(rotation),b0= s* sin(rotation),a1=tx,b1=ty.这样最后的相似变换结果为:
X = a0 * x - b0 * y + a1 = = s * x * cos(rotation) - s * y * sin(rotation) + a1 Y = b0 * x + a0 * y + b1 = = s * x * sin(rotation) + s * y * cos(rotation) + b1
三、相关方法: 3.1 estimate(self, src, dst):从一组对应点(源点,目标点)估计变换矩阵 输入参数: | src : (N, 2) array | Source coordinates.(源点坐标) | dst : (N, 2) array | Destination coordinates.(目标点坐标) 返回: | success : bool | True, if model estimation succeeds. 3.2 inverse(self, coords) :从目标坐标逆推源坐标 | Apply inverse transformation. 输入参数: | coords : (N, 2) array | Destination coordinates.(目标坐标) 返回: | coords : (N, 2) array | Source coordinates. 3.3 residuals(self, src, dst):确定转换后的目标坐标的残差,确定每个源坐标到各个目标坐标的欧几里德距离。 输入参数: | src : (N, 2) array | Source coordinates. | dst : (N, 2) array | Destination coordinates. 返回: | residuals : (N, ) array | Residual for coordinate. |
4、例子
4.1
- from skimage import transform as trans
- import numpy as np
- src = np.array([
- [38.2946, 51.6963],
- [73.5318, 51.5014],
- [56.0252, 71.7366],
- [41.5493, 92.3655],
- [70.7299, 92.2041] ], dtype=np.float32)
- dst = np.array([
- [38.2946, 51.6963],
- [73.5318, 51.5014],
- [56.0252, 71.7366],
- [41.5493, 92.3655],
- [70.7299, 92.2041] ], dtype=np.float32)
- tform = trans.SimilarityTransform()
- res =tform.estimate(dst, src)
- M = tform.params
- print(res)
- print(M)
【运行结果】:
4.2
- from skimage import io,data
- from skimage import transform as tf
- img = data.camera()
- io.imshow(img)
- tform = tf.SimilarityTransform(scale=1.5,rotation=np.deg2rad(10),translation=(10,12))
- img1 = tf.warp(img,tform)
- io.imshow(img1)
原图 相似变换后的图
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。