Search code examples
imagematlabimage-processingimage-effects

Ripple effect in MATLAB


I want to write a function newim = rippleim(im) that takes an image and returns a new image with ripple effect on it.

I thought calculating the distance of all points from (p,q) and then a multiplication of sin(d).*exp(-d) would give a good effect of fading waves.

n = 800;
m = 800;
im = zeros(n,m,3);
p = [round(m*.5) round(n*.5)];
[x y] = meshgrid(1:m,1:n);
x = x - p(1,1);
y = y - p(1,2);
d = (x .^2 + y .^2).^.5;
R = cos(.05*d) .* exp(-.005*d);
G = cos(.05*d) .* exp(-.005*d);
B = cos(.05*d) .* exp(-.005*d);
im = cat(3,R,G,B);
imshow(im);

And I got,

enter image description here

with normalization to [0 1], it got a little better,

enter image description here

It still doesn't seem right.

I even googled and found some similar cases in python here, about the animation. But I just want a fixed effect.

Q1 How to improve the effect?

Q2 How to apply it on an existing image?

Thanks,


Solution

  • I finally found my answer. What I was looking for, can be done by warp command.

    so I define a 3D rippled surface with help of cos(d)*exp(-d) and texture my picture on it.

    im = imread('peppers.png');
    n = -10 : .1 : 10;
    [X,Y] = meshgrid(n,n);
    d = (X .^ 2 + Y .^ 2) .^ .5;
    Z = cos(1.5 * d) .* exp(-.1 .* d);
    warp(X,Y,Z,im);axis equal;axis off;
    

    enter image description here