I would say the task using the pixel-by-pixel method is inappropriate for any device other than a high-end PC.
Ideally the image would be cropped to remove most of the background, leaving a smaller area to process. If the image has to arrive as-is, prompt the user to pick top left and bottom right points that define the area to be tested. However, the pixel-by-pixel method is still slow. Rather than test every pixel within the User-defined area, working left to right, once a pixel is hit that is not the background colour, we want to plot there and then test the surrounding pixels. So the code needs procedures for these little test areas to effectively only test in the region of the actual border and not all the pixels of the image. The code to do that type of test surely already exists - either as something that can be adapted and used on the App canvas (perhaps ImageMagik), or via an online service using the Custom Web View extension.