gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
29.49k stars 2.19k forks source link

The module gr.Sketchpad,ImageMask cannot obtain the binary image normally. #8198

Open JunchuanYu opened 2 weeks ago

JunchuanYu commented 2 weeks ago

Describe the bug

I want to obtain a binarized mask file through handwriting (with background as 0 and foreground as 1). However, when using gr.Sketchpador gr.ImageMask , if the image mode is set to "L", the output is an array of all zeros. when i change the color of the pencil to white, the output is correct, but i can't see what is draw. I found that this is because the program defaults to a background of all zeros and the pen default value is also zero, so the handwritten content cannot be seen. This is different from the old version of sketchpad.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
import numpy as np

def sleep(im):
    a=im["composite"]
    b=a.shape
    c=np.max(a)
    return a, f'the image size is {b},\n the max value is {c}'

with gr.Blocks() as demo:
    with gr.Group():
        with gr.Row():
            out=gr.Textbox() 
        with gr.Row():
            im = gr.Sketchpad(type="numpy",image_mode="L")
            im_out_1 = gr.Image(type="pil")
    im.change(sleep, outputs=[im_out_1, out], inputs=im)
    demo.launch()

Screenshot

111

Logs

No response

System Info

gradio==4.24.0
windows

Severity

I can work around it

JunchuanYu commented 2 weeks ago

gradio==4.27.0 windows