diff --git a/1..cpp b/1..cpp new file mode 100644 index 0000000..4eb2fcb --- /dev/null +++ b/1..cpp @@ -0,0 +1,67 @@ +#include +#include +#include + +#define KERNEL_SIZE 5 +#define IMAGE_SIZE 3 + +void applyGaussianBlur(int input[IMAGE_SIZE][IMAGE_SIZE], int output[IMAGE_SIZE][IMAGE_SIZE]) { +float kernel[KERNEL_SIZE][KERNEL_SIZE] = { +{1, 4, 6, 4, 1}, +{4, 16, 24, 16, 4}, +{6, 24, 36, 24, 6}, +{4, 16, 24, 16, 4}, +{1, 4, 6, 4, 1} +}; +float sum = 256.0; + +for (int i = 1; i < IMAGE_SIZE - 1; i++) { +for (int j = 1; j < IMAGE_SIZE - 1; j++) { +float blurred_value = 0.0; +for (int ki = 0; ki < KERNEL_SIZE; ki++) { +for (int kj = 0; kj < KERNEL_SIZE; kj++) { +int x = i - KERNEL_SIZE / 2 + ki; +int y = j - KERNEL_SIZE / 2 + kj; +blurred_value += input[x][y] * kernel[ki][kj]; +} +} +output[i][j] = (int)(blurred_value / sum); +} +} +} + +int main() { +int input[IMAGE_SIZE][IMAGE_SIZE] = { +{10, 20, 30}, +{40, 50, 60}, +{70, 80, 90} +}; +int output[IMAGE_SIZE][IMAGE_SIZE] = {{0}}; + +clock_t start = clock(); +applyGaussianBlur(input, output); +clock_t end = clock(); + +printf("Input Matrix:\n"); +for (int i = 0; i < IMAGE_SIZE; i++) { +for (int j = 0; j < IMAGE_SIZE; j++) { +printf("%d ", input[i][j]); +} +printf("\n"); +} + +printf("Output Matrix:\n"); +for (int i = 0; i < IMAGE_SIZE; i++) { +for (int j = 0; j < IMAGE_SIZE; j++) { +printf("%d ", output[i][j]); +} +printf("\n"); +} + +double time_spent = (double)(end - start) / CLOCKS_PER_SEC; +printf("Time spent: %f seconds\n", time_spent); + +return 0; +} + +