Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This is how I usually approach inpainting in HTML. I use three canvas objects: canvas_orig, canvas_mask, canvas_screen

  • Start with an image uploaded by the user or a URL
  • Load original image into an offscreen canvas, let's call it canvas_orig
  • Draw the the same image onto a canvas displayed to the user, that's canvas_screen. This is the only canvas visible to the user
  • Capture click and drag events for canvas_screen and draw them to another offscreen canvas, that's canvas_mask
  • Whenever canvas_mask changes, redraw canvas_orig onto canvas_screen and draw canvas_mask on top of it with some alpha (use CanvasRenderingContext2D.globalAlpha, see example at https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalAlpha)
  • When the user is done with drawing the mask, you send canvas_orig and canvas_mask off to your GPU provider (I use replicate https://replicate.com/)
  • Receive the result, store it in canvas_orig, clear canvas_mask and redraw `canv
@geronimi73
geronimi73 / 24-15.ipynb
Created December 15, 2024 09:38
My Dialog
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.