Define head function#ifndef ps_algorithm_h_included#define ps_algorithm_h_included#include <iostream># Include <string> #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 <time.h>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<octavecount; i++) {amplitude=std::p ow (Persistance, (octavecount-i)); Totalamplitude=totalamplitude+amplitude; Generate_smoothnoise (Base_noise, cloud_temp, i); Cloud=cloud+cloud_temp*amplitude; } cloud=cloud/totalamplitude; Show_image (Cloud, "out.jpg"); Imwrite ("Out.jpg", cloud*255); Waitkey ();} void Generate_smoothnoise (mat& src, mat& dst, int octave) {src.copyto (DST); int width=src.cols; int height=src.rows; Float Sampleperiod=pow (2,octave); float Samplefrequency=1/sampleperiod; int sample_i0, SAMPLE_I1; float vertical_blend, horizontal_blend; int sample_j0, sample_j1; float top, bottom; for (int i=0; i
Original
Opencv--perlin Noise