Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there no component specialized for inpainting in Gradio 4.x? #8692

Closed
1 task done
gibiee opened this issue Jul 3, 2024 · 5 comments
Closed
1 task done

Is there no component specialized for inpainting in Gradio 4.x? #8692

gibiee opened this issue Jul 3, 2024 · 5 comments
Assignees

Comments

@gibiee
Copy link
Contributor

gibiee commented Jul 3, 2024

  • I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.

  • In gradio 3.x, I often used gr.Image(tool='sketch') for implementing inpainting features.
  • However, it seems there is no component specialized for inpainting in Gradio 4.x.
  • To implement inpainting features in Gradio 4.x, I have to use gr.ImageEditor(brush=gr.Brush(~~~)), which I find not very intuitive.
  • Particularly, it's disappointing that I cannot see the brush area transparently.

Describe the solution you'd like

  • It would be great to have a component specialized for inpainting in Gradio 4.x.

Additional context

  • Below is a comparison between Gradio 3.x and 4.x regarding the functionality of converting mask area from RGB to BGR.
    compare
# python 3.10.14 / gradio 3.50.2

import gradio as gr
from PIL import Image
import numpy as np

def rgb_to_bgr(paint) :
    image, mask = paint['image'], paint['mask'].convert('L')
    image, mask = np.array(image), np.array(mask)

    mask_bool = np.where(mask > 128, True, False)
    image[mask_bool] = image[mask_bool, ::-1]
    return Image.fromarray(image)

with gr.Blocks() as demo:
    with gr.Row():
        input_img = gr.Image(label='Input', type='pil', image_mode='RGB', source='upload', tool='sketch')

        output_img = gr.Image(label='Output', type='pil', image_mode='RGB')
    
    with gr.Row() :
        btn = gr.Button("Run", variant="primary")

    btn.click(fn=rgb_to_bgr, inputs=[input_img], outputs=[output_img])

demo.launch()
# python 3.10.14 / gradio 4.37.2

import gradio as gr
from PIL import Image
import numpy as np

def rgb_to_bgr(paint) :
    image, mask = paint['background'], paint['layers'][0].convert('L')
    image, mask = np.array(image), np.array(mask)

    mask_bool = np.where(mask > 128, True, False)
    image[mask_bool] = image[mask_bool, ::-1]
    return Image.fromarray(image)

with gr.Blocks() as demo:
    with gr.Row():
        input_img = gr.ImageEditor(label='Input', type='pil', image_mode='RGB', sources=['upload'], layers=False,
                                   brush=gr.Brush(colors=["#AAAAAA"], color_mode="fixed"))

        output_img = gr.Image(label='Output', type='pil', image_mode='RGB')
    
    with gr.Row() :
        btn = gr.Button("Run", variant="primary")

    btn.click(fn=rgb_to_bgr, inputs=[input_img], outputs=[output_img])

demo.launch()
@pngwn
Copy link
Member

pngwn commented Jul 3, 2024

Does gr.ImageMask() address this issue (if we fixed the opacity issue)?

@gibiee
Copy link
Contributor Author

gibiee commented Jul 3, 2024

@pngwn
gr.ImageMask() is essentially just gr.ImageEditor(brush=Brush(colors=['#000000'], color_mode='fixed')), but if the opacity issue is resolved, it could be a useful component for inpainting. However, since the inpainting feature does not require layers and the mask image does not need to be RGB, I think it could be simplified further.

@pngwn
Copy link
Member

pngwn commented Jul 3, 2024

gr.ImageMask(layers=False) would be pretty close i think.

@gibiee
Copy link
Contributor Author

gibiee commented Jul 4, 2024

@pngwn
Yes, that is currently the method I often use.
Come to think of it, if the opacity issue is resolved, controlling the brush color in RGB might be helpful. Using a bright brush color for dark images and a dark brush color for light images would make them more visible.

@pngwn pngwn self-assigned this Jul 4, 2024
@abidlabs
Copy link
Member

Since we have a dedicated issue for opacity (#5644), I'll go ahead and close this.

@abidlabs abidlabs closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants