ImageTransform
模組¶
ImageTransform
模組包含一些內建的 Image.Transform
方法的 ImageTransformHandler
實作。
- class PIL.ImageTransform.Transform(data: Sequence[Any])[來源]¶
基底類別:
ImageTransformHandler
ImageTransform
中定義的其他轉換的基底類別。
- class PIL.ImageTransform.AffineTransform(data: Sequence[Any])[來源]¶
基底類別:
Transform
定義仿射影像轉換。
此函數接受一個 6 元組 (a, b, c, d, e, f),其中包含仿射轉換矩陣的前兩行。對於輸出影像中的每個像素 (x, y),新值取自輸入影像中的位置 (a x + b y + c, d x + e y + f),並四捨五入到最接近的像素。
此函數可用於縮放、平移、旋轉和剪切原始影像。
- 參數:
matrix – 包含仿射轉換矩陣前兩行的 6 元組 (a, b, c, d, e, f)。
- class PIL.ImageTransform.PerspectiveTransform(data: Sequence[Any])[來源]¶
基底類別:
Transform
定義透視影像轉換。
此函數接受一個 8 元組 (a, b, c, d, e, f, g, h)。對於輸出影像中的每個像素 (x, y),新值取自輸入影像中的位置 ((a x + b y + c) / (g x + h y + 1), (d x + e y + f) / (g x + h y + 1)),並四捨五入到最接近的像素。
此函數可用於縮放、平移、旋轉和剪切原始影像。
- 參數:
matrix – 8 元組 (a, b, c, d, e, f, g, h)。
- class PIL.ImageTransform.ExtentTransform(data: Sequence[Any])[原始碼]¶
基底類別:
Transform
定義一個轉換,從影像中提取一個子區域。
將影像中的一個矩形(由兩個角定義)映射到給定大小的矩形。產生的影像將包含從角之間採樣的數據,使得輸入影像中的 (x0, y0) 將在輸出影像中位於 (0,0),而 (x1, y1) 將位於 size。
此方法可用於裁剪、拉伸、縮小或鏡像目前影像中的任意矩形。它比裁剪稍微慢一些,但與相應的調整大小操作一樣快。
- 參數:
bbox – 一個 4 元組 (x0, y0, x1, y1),指定輸入影像座標系統中的兩個點。請參閱 座標系統。