zuruoke / watermark-removal

a machine learning image inpainting task that instinctively removes watermarks from image indistinguishable from the ground truth image
1.93k stars 300 forks source link

Only able to remove watermark from istock???? #40

Open ykhasia opened 2 months ago

ykhasia commented 2 months ago

As the argument "--watermark_type istock" indicates, this project could only remove watermark of istock image??? is so, what's the value of this project??? and is it necessary to make a such complex solution to remove the watermark of istock???

tomasvts commented 2 months ago

yes. It seems that If you want to remove other types of watermarks you have to create your own mask in: /utils/<yourmask>/landscape/mask.png

CelestialSpace commented 2 months ago

nb

AWangji commented 1 month ago

yes. It seems that If you want to remove other types of watermarks you have to create your own mask in: /utils/<yourmask>/landscape/mask.png

How to create this kind of mask?

tomasvts commented 1 month ago

@AWangji The mask must be a black background image. Additionally it must have 100% transparency on the spots you want to remove.
I mean, take for example the istock mask that is already in the repository. It is a black background image, and it has the characters to remove in a transparent layer.

cbt12123 commented 1 week ago

I wrote a code to generate masks:

import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageDraw, ImageTk
import numpy as np

class BrushTool:
    def __init__(self, root):
        self.root = root
        self.root.title("Brush Tool")

        # 设置画布
        self.canvas = tk.Canvas(self.root, bg='white')
        self.canvas.pack(fill=tk.BOTH, expand=True)

        # 设置笔刷默认大小
        self.brush_size = 10
        self.brush_color = "white"

        # 笔刷尺寸调整滑块
        self.size_slider = tk.Scale(self.root, from_=5, to=100, orient=tk.HORIZONTAL, label="Brush Size")
        self.size_slider.pack()

        # 选择文件按钮
        self.open_button = tk.Button(self.root, text="Open Image", command=self.open_image)
        self.open_button.pack(side=tk.LEFT)

        # 保存遮罩按钮
        self.save_button = tk.Button(self.root, text="Save Mask", command=self.save_mask)
        self.save_button.pack(side=tk.LEFT)

        # 初始化图像
        self.image = None
        self.mask = None
        self.mask_image = None

    def open_image(self):
        # 打开图像文件
        file_path = filedialog.askopenfilename()
        if file_path:
            self.image = Image.open(file_path)
            self.image = self.image.convert("RGB")
            self.mask = Image.new("L", self.image.size, 0)  # 初始化遮罩
            self.mask_draw = ImageDraw.Draw(self.mask)

            # 在画布上显示图像
            self.tk_image = ImageTk.PhotoImage(self.image)
            self.canvas.config(width=self.image.width, height=self.image.height)
            self.canvas.create_image(0, 0, anchor=tk.NW, image=self.tk_image)

            # 绑定鼠标拖动事件进行绘制
            self.canvas.bind("<B1-Motion>", self.paint)

    def paint(self, event):
        # 获取笔刷大小
        self.brush_size = self.size_slider.get()
        # 绘制笔刷路径(在遮罩上绘制白色区域)
        self.mask_draw.ellipse([event.x - self.brush_size, event.y - self.brush_size, 
                                event.x + self.brush_size, event.y + self.brush_size], 
                                fill=255)

        # 在画布上绘制笔刷效果
        self.canvas.create_oval(event.x - self.brush_size, event.y - self.brush_size, 
                                event.x + self.brush_size, event.y + self.brush_size, 
                                fill=self.brush_color, outline=self.brush_color)

    def save_mask(self):
        if self.image is not None:
            # 创建最终输出图像(RGBA)
            output_image = Image.new("RGBA", self.image.size, (0, 0, 0, 255))

            # 遮罩部分变透明,其他部分保持黑色
            output_np = np.array(output_image)
            mask_np = np.array(self.mask)
            output_np[:, :, 3] = 255 - mask_np  # 将笔刷部分设置为透明

            # 保存结果
            result = Image.fromarray(output_np)
            result.save("output_mask.png")
            print("Mask saved as output_mask.png")

if __name__ == "__main__":
    root = tk.Tk()
    app = BrushTool(root)
    root.mainloop()

The mask generated by this code cannot achieve background removal effect.