Image processing water ripple effect

To sum up, the circle of the water wave is gradually expanded from 0-R and displayed frame by frame. While enlarging, the pixel point is endowed with a wave function and energy-decreasing transformation. The color is to round the four directions of the pixel point (color neighborhood), multiply the weight value, and finally assign it back to the point.

The center of the ripple generation point, the radius of the ripple, etc. can be randomly and automatically selected.

Logically, it should be displayed dynamically, but due to the size of the video and gif images cannot be placed, the final effect can only be displayed in the blog.

The picture below is the effect:

Determine the ripple range code:

 dis=dx*dx+dy*dy;
 if dis>R*R || dis==0
     new=[i j k];
else
     dis=sqrt(dis);
a= ((R-dis) * wave*l * sin(dis/wave * 2*pi))/(R*dis); %圆形波动+能量递减(R-dis)/R
*dis去模拟水波效果    
i1=(i+dy*a);         %获得迁移变量
j1=(j+dx*a);         %获得迁移变量

Water wave effect energy transformation core code:

float_Y=new(1)-floor(new(1)); %这一步可以算是归一化,方便计算后面四个点的权重
float_X=new(2)-floor(new(2));
new_up_left=[floor(new(1)) floor(new(2)) ];          %获得像素位置的四个邻域
new_up_right=[floor(new(1)) ceil(new(2)) ];
new_down_left=[ceil(new(1)) floor(new(2)) ];
new_down_right=[ceil(new(1)) ceil(new(2)) ];
value_up_left=(1-float_X)*(1-float_Y);              %计算临近四个点的权重,进行插值
value_up_right=float_X*(1-float_Y);
value_down_left=(1-float_X)*float_Y;
value_down_right=float_X*float_Y;       
imgn(i,j,k)=value_up_left*img(new_up_left(1),new_up_left(2),new(3))+ ...
value_up_right*img(new_up_right(1),new_up_right(2),new(3))+ ...
                                
value_down_left*img(new_down_left(1),new_down_left(2),new(3))+ ...
                               
value_down_right*img(new_down_right(1),new_down_right(2),new(3));%将该点计算后的颜色结果赋予该点

Guess you like

Origin blog.csdn.net/qq_52913088/article/details/125349877