clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread('4.jpg'); Image=double(I)/255; [height, width, depth]=size(Image); rays = 25; radius = 25; amount = 25; % 1-100 color = [1.0, 1.0, 1.0]; % 0-1 randomness = 25; centreX=width/2.0; centreY=height/2.0; % % seed = 371; rayLengths=radius+randomness / 100.0 * radius * rand(1,rays); Img_new=Image; for ii=1:height for jj=1:width dx = jj-centreX; dy = ii-centreY; distance=sqrt(dx*dx+dy*dy); angle = atan2(dy, dx); d = (angle+pi) / (2*pi) * rays; f=d-floor(d); len_1=rayLengths(mod(floor(d), rays)+1); len_2=rayLengths(mod(floor(d)+1, rays)+1); length = lerp(f, len_1, len_2); g = length*length / (distance+0.0001); g = g.^((100-amount) / 50.0); f =f - 0.5; % % f = 1-f*f; f =f * cos(g); % % f =f * sin(g); f=min(max(0,f),1); r=Image(ii, jj, 1); g=Image(ii, jj, 2); b=Image(ii, jj, 3); Img_new(ii, jj, 1)=lerp(f, r, color(1)); Img_new(ii, jj, 2)=lerp(f, g, color(2)); Img_new(ii, jj, 3)=lerp(f, b, color(3)); end end imshow(Img_new); imwrite(Img_new, 'out.jpg');
参考来源:
原图:
效果图: