本文主要是介绍利用Perlin nosie 完成(PS 滤镜—— 分成云彩),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
%%%% Cloud
%%%% 利用perlin noise生成云彩clc;
clear all;
close all;addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');Image=imread('4.jpg');
Image=double(Image);[row,col,layer]=size(Image);baseNoise=rand(row,col);persistance = 0.9;
totalAmplitude = 0.0;octaveCount=10;Cloud_texture=zeros(row,col);for i=0:octaveCountamplitude=persistance.^(octaveCount-i);% amplitude=persistance.^i;totalAmplitude=totalAmplitude+amplitude;Cloud_texture=Cloud_texture+Generate_smoothnoise(baseNoise, i)*amplitude;
endCloud_texture=Cloud_texture/totalAmplitude;imshow(Cloud_texture);function SmoothNoise=Generate_smoothnoise(baseNoise, octave)SmoothNoise=baseNoise;[row, col]=size(baseNoise);samplePeriod=2.^octave;
sampleFrequency=1/samplePeriod;for i=1:rowsample_i0=floor((i/samplePeriod))*samplePeriod;sample_i1=mod(sample_i0+samplePeriod,row);vertical_blend = (i - sample_i0) * sampleFrequency;for j=1:colsample_j0 = floor(j / samplePeriod) * samplePeriod;sample_j1 = mod(sample_j0 + samplePeriod,col);horizontal_blend = (j - sample_j0) * sampleFrequency;if(sample_i0<1)sample_i0=1;endif(sample_i1<1)sample_i1=1;endif(sample_j1<1)sample_j1=1;endif(sample_j0<1)sample_j0=1;end% blend the top two cornerstop = Cosine_Interpolate(baseNoise(sample_i0,sample_j0),...baseNoise(sample_i0,sample_j1), horizontal_blend);% blend the bottom two cornersbottom = Cosine_Interpolate(baseNoise(sample_i1,sample_j0),...baseNoise(sample_i1,sample_j1), horizontal_blend);% final blendSmoothNoise(i,j) = Cosine_Interpolate(top, bottom, vertical_blend);end
endfunction y=Cosine_Interpolate(x1,x2,alpha)ft = alpha * 3.1415927;
f = (1 - cos(ft)) * .5;y=x1*(1-f)+x2*f;
原图
效果图
这篇关于利用Perlin nosie 完成(PS 滤镜—— 分成云彩)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!