OpenCV -- Perlin Noise

Source: Internet
Author: User

OpenCV -- Perlin Noise

// define head function#ifndef PS_ALGORITHM_H_INCLUDED#define PS_ALGORITHM_H_INCLUDED#include 
 
  #include 
  
   #include "cv.h"#include "highgui.h"#include "cxmat.hpp"#include "cxcore.hpp"#include "math.h"using namespace std;using namespace cv;void Show_Image(Mat&, const string &);#endif // PS_ALGORITHM_H_INCLUDED/*perlin noise.*/#include "PS_Algorithm.h"#include 
   
    using namespace std;using namespace cv;void Generate_smoothnoise(Mat& src, Mat& std, int octave);float Cosine_Interpolate(float x1,float x2,float alpha);#define pi 3.1415926int main(){    string Img_name("4.jpg");    Mat Img;    Img=imread(Img_name);    Mat Cloud(Img.size(), CV_32FC1);    Mat Cloud_Temp(Img.size(), CV_32FC1);    Mat Base_Noise(Img.size(), CV_32FC1);    cv::randn(Base_Noise, 0.5, 0.25);    // Show_Image(Base_Noise, "N1");    float persistance = 0.8;    float totalAmplitude = 0.0;    float amplitude;    int octaveCount=8;    for (int i=0; i
    
     (sample_i0,sample_j0),                    src.at
     
      (sample_i0,sample_j1), horizontal_blend);            // blend the bottom two corners            bottom = Cosine_Interpolate(src.at
      
       (sample_i1,sample_j0), src.at
       
        (sample_i1,sample_j1), horizontal_blend); // final blend dst.at
        
         (i,j) = Cosine_Interpolate(top, bottom, vertical_blend); } }}float Cosine_Interpolate(float x1,float x2,float alpha){ float ft, f; float y; ft = alpha * pi; f = (1 - cos(ft)) * .5; y=x1*(1-f)+x2*f; return y;}// define the show image#include "PS_Algorithm.h"#include 
         
          #include 
          
           using namespace std;using namespace cv;void Show_Image(Mat& Image, const string& str){ namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE); imshow(str.c_str(), Image);}
          
         
        
       
      
     
    
   
  
 

Source image

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.