• 利用Perlin nosie 完毕(PS 滤镜—— 分成云彩)


    %%%% Cloud
    %%%% 利用perlin noise生成云彩
    
    clc;
    clear all;
    close all;
    
    addpath('E:PhotoShop AlgortihmImage ProcessingPS 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:octaveCount
        amplitude=persistance.^(octaveCount-i);
        % amplitude=persistance.^i;
        totalAmplitude=totalAmplitude+amplitude;
        Cloud_texture=Cloud_texture+Generate_smoothnoise(baseNoise, i)*amplitude;
    end
    
    Cloud_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:row
        sample_i0=floor((i/samplePeriod))*samplePeriod;
        sample_i1=mod(sample_i0+samplePeriod,row);
        vertical_blend = (i - sample_i0) * sampleFrequency;
        for j=1:col
            sample_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;
            end
            
            if(sample_i1<1)
                sample_i1=1;
            end
            
            if(sample_j1<1)
                sample_j1=1;
            end
            
            if(sample_j0<1)
                sample_j0=1;
            end
            
            % blend the top two corners
            top = Cosine_Interpolate(baseNoise(sample_i0,sample_j0),...
            baseNoise(sample_i0,sample_j1), horizontal_blend);
     
            % blend the bottom two corners
            bottom = Cosine_Interpolate(baseNoise(sample_i1,sample_j0),...
            baseNoise(sample_i1,sample_j1), horizontal_blend);
     
            % final blend
            SmoothNoise(i,j) = Cosine_Interpolate(top, bottom, vertical_blend);
        end
    end
    
    
    
    function  y=Cosine_Interpolate(x1,x2,alpha)
    
    
    ft = alpha * 3.1415927;
    f = (1 - cos(ft)) * .5;
    
    y=x1*(1-f)+x2*f;
    


    原图


    效果图


  • 相关阅读:
    指针数组和数组指针表示二维数组
    scanf与getchar()区别
    选择循环
    朴素的思想
    asp.net中word转html碰到的权限异常问题(转)
    MAC下安装Fiddler抓包工具
    抓包工具charles的使用
    mysql 命令大全
    利用反射拼接SQL查询条件字符串
    赚自己的淘宝佣金,让返利网无路可走
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7267718.html
Copyright © 2020-2023  润新知