Search code examples
dynamicwolfram-mathematicamathematica-8

Filter & Manipulate CurrentImage []


Please consider the following (I am using Mathematica 8) :

mask = DensityPlot[-Exp[-(x^2 + y^2)/5], {x, -4, 4}, {y, -3, 4}, 
       Axes -> None, Frame -> None, Method -> {"ShrinkWrap" -> True}, 
       ColorFunction -> GrayLevel, ImageSize -> 512];

       Show[ImageFilter[Mean[Flatten[#]] &, CurrentImage[], 20, 
            Masking -> mask], ImageSize -> 512]

using Sjoerd solution on Can we generate "foveated Image" in Mathematica.

I would like this to be dynamic. Right now it only takes a picture. What would be the best way to get this to work "live" without crashing my computer during my presentation ? Could I adjust the refresh rate ? Manipulate the mask ? Stop the "video mode" to take a picture ?


Solution

  • Just wrap your Show in Dynamic and it will update as fast as it can. Combine with Refresh to set a refresh rate. Or use a timed background task.

    The result is a bit slow though as the handcrafted blur filter takes too long. A better alternative would be something like:

    mask = DensityPlot[-Exp[-(x^2 + y^2)/5], {x, -4, 4}, {y, -3, 3}, 
       Axes -> None, Frame -> None, Method -> {"ShrinkWrap" -> True}, 
       ColorFunction -> GrayLevel, ImageSize -> {320, 240}];
    
    ImageCompose[im = CurrentImage[], SetAlphaChannel[Blur[im, 20], mask]]//Dynamic
    

    which updates in real time. Note that I have changed the image dimensions of the mask to fit the size of my laptop camera. The x and y range ratio should be the same as the camera's aspect ratio.

    enter image description here

    Remember, as mentioned before, this only fakes visual blurring. It is far from reality.