I use this formula to turn my shapes into grayscale.
R x 0.2126 + G x 0.7152 + B x 0.0722
Now which algorithm I can use use to remove the background of a shape in a canvas like this.
Or this.
In this specific case, my goal is to obtain the first symbol ("a") and the second symbol ("p") with a transparent background.