Remove White Background from an Image and Make It Transparent

This function implements the reverse blend described by Mark Ransom, for an additional small but visible improvement: reverseBlend[img_Image, alpha_Image, bgcolor_] := With[ {c = ImageData[img], a = ImageData[alpha] + 0.0001, (* this is to minimize ComplexInfinitys and considerably improve performance *) bc = bgcolor}, ImageClip@ Image[Quiet[(c – bc (1 – a))/a, {Power::infy, Infinity::indet}] /. {ComplexInfinity … Read more

How do I find Waldo with Mathematica?

I’ve found Waldo! How I’ve done it First, I’m filtering out all colours that aren’t red waldo = Import[“http://www.findwaldo.com/fankit/graphics/IntlManOfLiterature/Scenes/DepartmentStore.jpg”]; red = Fold[ImageSubtract, #[[1]], Rest[#]] &@ColorSeparate[waldo]; Next, I’m calculating the correlation of this image with a simple black and white pattern to find the red and white transitions in the shirt. corr = ImageCorrelate[red, Image@Join[ConstantArray[1, {2, … Read more

Preventing avalanche of runtime errors in Mathematica

As others have pointed out, there are three ways to deal with errors in a consistent manner: correctly typing parameters and setting up conditions under which your functions will run, dealing correctly and consistently with errors generated, and simplifying your methodology to apply these steps. As Samsdram pointed out, correctly typing your functions will help … Read more