You should be able to do something similar to this, albeit probably quite slowly using canvas.
See this post for how to grab the pixel colour after converting your image to a canvas representation:
How to get a pixel's x,y coordinate color from an image?.
You would have to replace event.OffsetX and event.OffsetY with the coordinate of each individual pixel using a for
loop to retrieve the RGB of each pixel. Then, if it doesn't match the blue's RGB values, replace the pixel colour with black, and if it is the blue, replace it with white.
It would be pretty damn slow, borderline probably not doable without locking up the browser (I haven't personally worked with canvas yet to know its performance), unless you offload it to a web worker so it happens in another thread.