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
30.84k stars 2.3k forks source link

[ImageEditor] - Allow the sketch tool to disable anti-aliasing #3252

Open pngwn opened 1 year ago

pngwn commented 1 year ago

Is your feature request related to a problem? Please describe.
We anti alias sketch lines so they look pretty which is nice for freehand sketches but not so nice for masks/ segmentation maps.

Describe the solution you'd like
It would be nice if the application author could disable the anti-aliasing behaviour.

Additional context

Current behaviour

image

Usecase

image (1)
pngwn commented 1 year ago

This is far more involved than I first thought, will need a completely custom implementation. Antialiasing cannot be disabled at all for canvas which makes sense jn principle but is still annoying.

abidlabs commented 1 year ago

I wonder if we can do it in Python as part of the postprocessing, via a top_k_colors parameter (cc @apolinario)

apolinario commented 1 year ago

I wonder if we can do it in Python as part of the postprocessing, via a top_k_colors parameter (cc @apolinario)

IMO that may be a sub-optimal solution for the following reasons: 1) The developer may not know how many colors the users are going to draw in their segmentation mask - so there would need to be a heuristic to try to detect which colors are masks and which are edges 2) I'm actually experimenting with doing this on post-processing myself while we don't have this, and top_k_colors sometimes behave sub-optimally - for example in a demo like this below - in a color with a lot of surface area sometimes an anti-aliased red would get a higher frequency (and would get into the top ranking) than a small mask (like the purple one in this case)

image
pngwn commented 7 months ago

This should be possible with the new ImageEditor, the only reason i didn't add it is that I didn't have time to confirm that it worked as expected.