本文共 1129 字,大约阅读时间需要 3 分钟。
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),tx为向左平移的像素数,ty为向上平移的像素数
返回:
一个 skimage.transform._geometric.SimilarityTransform object
例如:
tform = tf.SimilarityTransform(scale=1.5,rotation=np.deg2rad(10),translation=(10,12)) # 缩放1.5倍,逆时针旋转10度,向左平移10pix,向上平移12pix
from numpy import arrayfrom skimage import transform as transimport numpy as npfrom PIL import Imageimg = Image.open('dog.png')# img.show()tform = trans.SimilarityTransform(scale=1.5,rotation=np.deg2rad(10),translation=(10,12)) # 图像转换规则tform = trans.SimilarityTransform() # 什么转换都不做img1 = array(img,'f')# 将图像转为数组类型,由于可能对im1直接进行运算,对整型的像素数据的除运算,会导致小数丢失。故需要增加'f'optionimg2 = trans.warp(img1,tform) # 进行图像变换img2=Image.fromarray(np.uint8(img2)) # 从array类型转为图像类型img2.show()
转换前后的变换:
转载地址:https://mapengsen.blog.csdn.net/article/details/117919117 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!