What version of Mathematica are you using? In Mathematica 8, you can use SetAlphaChannel
. for instance
transparent2[img_] := SetAlphaChannel[img, Binarize[ColorNegate[img], 0.]]
will set the alpha channel of all white pixels to 0 and all other pixels to 1. I tested this on
img = Image[Graphics3D[Sphere[], Background -> White], ImageSize -> 1000]
and the timers that I get
transparent2[img]; // Timing (* ==> {0.10067, Null} *)
compared to the source code
transparent[img]; //Timing (* ==> {0.202112, Null} *)
Heike source share