身内の宣伝コーナー
フルオーダーから既製デザイン柔軟に対応!
袴ロンパースの製作販売してます!レンタルもやってます!
大口注文やレンタルのサブスクなど相談ください!
よかったら見てみてね
ココから本題
この記事を見てやりました。
----------------------
import tkinter as tk
from tkinter import filedialog
from rembg import remove
from PIL import Image
def select_input_file():
file_path = filedialog.askopenfilename(title="Select Input Image", filetypes=[("Image files", "*.png;*.jpg;*.jpeg")])
input_entry.delete(0, tk.END)
input_entry.insert(0, file_path)
def select_output_file():
file_path = filedialog.asksaveasfilename(title="Select Output Image", defaultextension=".png", filetypes=[("PNG files", "*.png")])
output_entry.delete(0, tk.END)
output_entry.insert(0, file_path)
def remove_background():
input_path = input_entry.get()
output_path = output_entry.get()
if input_path and output_path:
input_image = Image.open(input_path)
output_image = remove(input_image)
output_image.save(output_path)
result_label.config(text="Background removed successfully!")
# GUIの作成
root = tk.Tk()
root.title("Background Removal Tool")
# 入力ファイルの選択
input_label = tk.Label(root, text="Select Input Image:")
input_label.pack()
input_entry = tk.Entry(root, width=50)
input_entry.pack()
input_button = tk.Button(root, text="Browse", command=select_input_file)
input_button.pack()
# 出力先の指定
output_label = tk.Label(root, text="Select Output Image:")
output_label.pack()
output_entry = tk.Entry(root, width=50)
output_entry.pack()
output_button = tk.Button(root, text="Browse", command=select_output_file)
output_button.pack()
# バックグラウンドの削除ボタン
remove_button = tk.Button(root, text="Remove Background", command=remove_background)
remove_button.pack()
# 結果表示用ラベル
result_label = tk.Label(root, text="")
result_label.pack()
# GUIの実行
root.mainloop()
----------------------
実行すると
こんなGUIが出て、入力、出力を選択すると
こういう透過ができる
色々使えそうでいいですね
GUIにしたほうが実用性もあるし助かりますな
ココまで
私自身の活動案内
(ココナラで出品中)
この記事の関連商品