Advertisement
shiftry123

Untitled

Jan 27th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #define STB_IMAGE_IMPLEMENTATION
  2. #define STB_IMAGE_WRITE_IMPLEMENTATION
  3. #define STBI_MSC_SECURE_CRT
  4. #define M_PI 3.14159265358979323846
  5.  
  6. #include "stb_image.h"
  7. #include "stb_image_write.h"
  8.  
  9. #include <cmath>
  10. #include <algorithm>
  11. #include <iostream>
  12. #include <cstdint>
  13.  
  14. extern "C"
  15. {
  16.     void blur(uint32_t* source, uint32_t* target, float* kernel, uint32_t width, uint32_t height, uint32_t kernel_size, float weight_sum);
  17. }
  18.  
  19. int main()
  20. {
  21.     int width = 0, height = 0, channels = 0;   
  22.     uint32_t* source = new uint32_t[width*height];//(uint32_t*)stbi_load("test.jpg", &width, &height, &channels, 4);
  23.     uint32_t* target = new uint32_t[width*height];
  24.  
  25.     const float sigma = 50 / 2.57;
  26.     const int radius = ceil(50);
  27.     const float exp_denom = 2 * sigma * sigma;
  28.     const float gauss_denom = sqrt(M_PI * 2 * sigma * sigma);
  29.  
  30.     float* weight = new float[2 * radius + 1];
  31.     float weight_sum = 0;
  32.     for (int i = 0; i < 2 * radius + 1; i++)
  33.     {
  34.         const int numerator = (i - radius) * (i - radius);
  35.         weight[i] = exp(-numerator / exp_denom) / gauss_denom;
  36.         weight_sum += weight[i];
  37.     }
  38.  
  39.     blur((int*)1, (int*)2, (float*)3, 4, 5, 6, 7);
  40.  
  41.     blur(source, target, weight, width, height, 2*radius, 1/weight_sum);
  42.     stbi_write_jpg("test_output.jpg", width, height, 4, target, 100);
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement