clc;
clear all;
close all;
addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
I=imread('4.jpg');
Image=double(I)/255*0;
[height, width, depth]=size(Image);
rays = 200;
radius=100;
baseAmount = 1.0;
ringAmount = 0.25;
rayAmount = 0.15;
color = [1.0, 1.0, 1.0];
centreX = 0.7;
centreY = 0.3;
ringWidth = 1.5;
linear = 0.025;
gauss = 0.005;
mix = 0.50;
falloff = 5.0;
sigma=radius/6;
icentreX = centreX*width;
icentreY = centreY*height;
[p, g1, g2, g3]=init_arr();
Img_new=Image;
for ii=1:height
for jj=1:width
dx = jj-icentreX;
dy = ii-icentreY;
distance=sqrt(dx*dx+dy*dy);
a = exp(-distance*distance*gauss)*mix + exp(-distance*linear)*(1-mix);
a=a*baseAmount;
if (distance > radius + ringWidth)
a =lerp((distance - (radius + ringWidth))/falloff, a, 0);
end
if (distance < radius - ringWidth || distance > radius + ringWidth)
ring = 0;
else
ring = abs(distance-radius)/ringWidth;
ring = 1 - ring*ring*(3 - 2*ring);
ring = ring*ringAmount;
end
a=a+ring;
angle =atan2(dx, dy)+pi;
angle = (mod(angle/pi*17 + 1.0 + Noise1(angle*10, p, g1), 1.0) - 0.5)*2;
angle = abs(angle);
angle = angle.^5;
b = rayAmount * angle / (1 + distance*0.1);
a = a + b;
a=min(max(0,a),1);
r=Image(ii, jj, 1);
g=Image(ii, jj, 2);
b=Image(ii, jj, 3);
Img_new(ii, jj, 1)=lerp(a, r, color(1));
Img_new(ii, jj, 2)=lerp(a, g, color(2));
Img_new(ii, jj, 3)=lerp(a, b, color(3));
end
end
imshow(Img_new);
imwrite(Img_new, 'out.jpg');
参考来源:http://www.jhlabs.com/index.html
效果图: