简单的matlab哈哈镜

来源:互联网 发布:硬笔字 知乎 编辑:程序博客网 时间:2024/04/28 07:11


clc;close all;clear all; path1 = 'e:\img\ds2.jpg';  im1 = imread(path1);    [m,n,c] = size(im1);ratio = 400  / min(m,n); im1 = imresize(im1, ratio);   [m,n,c] = size(im1);im1 = im2double(im1);  figure; imshow(im1); title('原图'); im2 = zeros(m,n,3); figure;  times = 0; while times < 20    times = times+1;     r1 = rand;    r2 = rand;    r3 = rand;    r4 = rand;    for i=1:m            ty = i - cos(-i*0.02 *r1*pi + r3 )*m/30;         ty = round(ty);         ty = min(ty, m);         ty = max(1, ty);         for j = 1:n            tx = j + sin(-j*0.02 *r2*pi + r4)*n/30;             tx = round(tx);             tx = min(tx, n);             tx = max(1, tx);             im2(i, j, :) = im1(ty, tx, :);         end     end     imshow(im2); title('matlab哈哈镜');      drawnow; end  


0 0