
- Python Pillow 教程
- Python Pillow - 首頁
- Python Pillow - 概述
- Python Pillow - 環境搭建
- 基本影像操作
- Python Pillow - 影像處理
- Python Pillow - 調整影像大小
- Python Pillow - 翻轉和旋轉影像
- Python Pillow - 裁剪影像
- Python Pillow - 為影像新增邊框
- Python Pillow - 識別影像檔案
- Python Pillow - 合併影像
- Python Pillow - 影像剪下和貼上
- Python Pillow - 影像滾動
- Python Pillow - 在影像上新增文字
- Python Pillow - ImageDraw 模組
- Python Pillow - 合併兩張影像
- Python Pillow - 建立縮圖
- Python Pillow - 建立水印
- Python Pillow - 影像序列
- Python Pillow 顏色轉換
- Python Pillow - 影像顏色
- Python Pillow - 使用顏色建立影像
- Python Pillow - 將顏色字串轉換為 RGB 顏色值
- Python Pillow - 將顏色字串轉換為灰度值
- Python Pillow - 透過更改畫素值來更改顏色
- 影像處理
- Python Pillow - 降噪
- Python Pillow - 更改影像模式
- Python Pillow - 影像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 應用透視變換
- 影像濾鏡
- Python Pillow - 為影像新增濾鏡
- Python Pillow - 卷積濾鏡
- Python Pillow - 模糊影像
- Python Pillow - 邊緣檢測
- Python Pillow - 浮雕影像
- Python Pillow - 增強邊緣
- Python Pillow - 銳化蒙版濾鏡
- 影像增強和校正
- Python Pillow - 增強對比度
- Python Pillow - 增強銳度
- Python Pillow - 增強色彩
- Python Pillow - 校正色彩平衡
- Python Pillow - 去噪
- 影像分析
- Python Pillow - 提取影像元資料
- Python Pillow - 識別顏色
- 高階主題
- Python Pillow - 建立動畫 GIF
- Python Pillow - 批次處理影像
- Python Pillow - 轉換影像檔案格式
- Python Pillow - 為影像新增填充
- Python Pillow - 顏色反轉
- Python Pillow 與 Numpy 的機器學習
- Python Pillow 與 Tkinter BitmapImage 和 PhotoImage 物件
- Image 模組
- Python Pillow - 影像混合
- Python Pillow 有用資源
- Python Pillow - 快速指南
- Python Pillow - 函式參考
- Python Pillow - 有用資源
- Python Pillow - 討論
Python Pillow - ImageChops.duplicate() 函式
PIL.ImageChops.duplicate() 函式是 PIL.Image.Image.copy() 方法的別名。兩者執行相同的操作,它們建立輸入影像的副本(複製)。複製的目的是允許修改複製的影像,同時保持原始影像不變。
語法
以下是函式的語法:
PIL.ImageChops.duplicate(image)
或者
PIL.Image.Image.copy()
引數
以下是其引數的詳細資訊:
Image - 要建立副本的影像物件。
返回值
該函式返回一個 Image 物件,它是輸入影像的副本(複製)。
示例
示例 1
此示例演示了以兩種不同方式複製影像的過程:使用 ImageChops.duplicate() 函式和使用 copy() 方法。
from PIL import Image, ImageChops # Open the original image original_image = Image.open('Images/Car_2.jpg') # Duplicate the original image using the ImageChops.duplicate() function duplicated_image = ImageChops.duplicate(original_image) # Duplicate the original image using the copy() method image_copy = original_image.copy() # Print the IDs of the original and duplicated images print('IDs of the Image objects') print('Original Image:', id(original_image)) print('Duplicated Image:',id(duplicated_image)) print('Copied Image:', id(image_copy))
輸出
IDs of the Image objects Original Image: 1568872675552 Duplicated Image: 1568861890592 Copied Image: 1568861889968
您可以看到,這兩種方法都建立了原始影像的獨立副本,每個副本都有唯一的標識。
示例 2
以下示例演示如何使用 ImageChops.duplicate() 方法建立影像副本,然後將另一個影像貼上到副本上,而不會影響原始影像,然後顯示兩張影像進行比較。
from PIL import Image, ImageChops # Open the original image and logo image = Image.open('Images/Car_2.jpg') logo = Image.open('Images/tutorialspoint2.jpg') # Duplicate the original image image_copy = ImageChops.duplicate(image) # Get the position to paste the logo position = ((image_copy.width - logo.width), (image_copy.height - logo.height)) # Paste the logo onto the duplicated image image_copy.paste(logo, position) # Display the duplicated and original images image_copy.show() image.show()
輸出
原始影像

複製的影像

您可以觀察到,即使在對副本進行修改後,原始影像也保持不變。
示例 3
以下示例演示如何使用 Image.copy() 方法建立影像副本,然後將另一個影像貼上到副本上,而不會影響原始影像。之後,顯示兩張影像進行比較。
from PIL import Image, ImageDraw # Open the original image and logo original_image = Image.open('Images/Car_2.jpg') logo = Image.open('Images/tutorialspoint2.jpg') # Duplicate the original image duplicated_image = original_image.copy() # Get the position to paste the logo position = ((duplicated_image.width - logo.width), (duplicated_image.height - logo.height)) # Paste the logo onto the duplicated image duplicated_image.paste(logo, position) # Display both the duplicated and original images duplicated_image.show() original_image.show()
輸出
原始影像

複製的影像

python_pillow_function_reference.htm
廣告