// 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.1415926 int 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); }
原圖
效果圖