Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define STB_IMAGE_IMPLEMENTATION
- #define STB_IMAGE_WRITE_IMPLEMENTATION
- #define STBI_MSC_SECURE_CRT
- #define M_PI 3.14159265358979323846
- #include "stb_image.h"
- #include "stb_image_write.h"
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <cstdint>
- extern "C"
- {
- void blur(uint32_t* source, uint32_t* target, float* kernel, uint32_t width, uint32_t height, uint32_t kernel_size, float weight_sum);
- }
- int main()
- {
- int width = 0, height = 0, channels = 0;
- uint32_t* source = new uint32_t[width*height];//(uint32_t*)stbi_load("test.jpg", &width, &height, &channels, 4);
- uint32_t* target = new uint32_t[width*height];
- const float sigma = 50 / 2.57;
- const int radius = ceil(50);
- const float exp_denom = 2 * sigma * sigma;
- const float gauss_denom = sqrt(M_PI * 2 * sigma * sigma);
- float* weight = new float[2 * radius + 1];
- float weight_sum = 0;
- for (int i = 0; i < 2 * radius + 1; i++)
- {
- const int numerator = (i - radius) * (i - radius);
- weight[i] = exp(-numerator / exp_denom) / gauss_denom;
- weight_sum += weight[i];
- }
- blur((int*)1, (int*)2, (float*)3, 4, 5, 6, 7);
- blur(source, target, weight, width, height, 2*radius, 1/weight_sum);
- stbi_write_jpg("test_output.jpg", width, height, 4, target, 100);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement