Member-only story

Python 解鎖: Image Tricks

DigNo Ape
Dec 3, 2024

--

!pip install rembg pillow onnxruntime

from google.colab import drive
from google.colab import files

drive.mount('/content/drive')

from rembg import remove
from PIL import Image
import os

圖片去背

使用 rembg 套件來移除存於 Google Drive的 台灣隊長陳傑憲 圖片背景,並將處理後的圖片存於Google Drive。

# 定義 Google Drive 的目錄
drive_folder = "/content/drive/MyDrive/processed_images/"

# 確保資料夾存在
os.makedirs(drive_folder, exist_ok=True)

# 打開輸入影像
input_image = Image.open('images.jpg')

# 移除影像背景
output_image = remove(input_image)

# 儲存在 Google Drive 的路徑
output_path = os.path.join(drive_folder, 'image_processed.png')

# 儲存處理後的影像到 Google Drive
output_image.save(output_path)
print(f"處理後的影像已儲存到:{output_path}")

圖片Mirror

使用 rembg 套件來 mirror 存於Google Drive的 台灣隊長陳傑憲 圖片,並將處理後的圖片存於Google Drive。

# 打開輸入影像
input_image = Image.open('/content/drive/MyDrive/processed_images/images.jpg')

# 生成鏡像圖片
Mirror_Image = input_image.transpose(Image.FLIP_LEFT_RIGHT)

# 儲存鏡像圖片
Mirror_Image.save('/content/drive/MyDrive/processed_images/mirror.jpg')

# 打開鏡像圖片…

--

--

DigNo Ape
DigNo Ape

Written by DigNo Ape

我們秉持著從原人進化的精神,不斷追求智慧的累積和工具的運用來提升生產力。我們相信,每一個成員都擁有無限的潛力,透過學習和實踐,不斷成長和進步。

No responses yet