Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in C++ Gaussian Blur In image editing software, an image can be blurred by replacing a pixel's value with the average of a group

Code in C++

Gaussian Blur

In image editing software, an image can be blurred by replacing a pixel's value with the average of a group of pixels around it. The following code provides you with an "image" as a two-dimensional array. Your task is to write a function which takes this image and blurs it using the following algorithm:

For every pixel, replace it's value with the average of five pixels including the pixel itself, as well as the four surrounding pixels above, below, to the left and to the right of it. Average these five values together and update the value. For pixels touching an edge or corner, assume the values of pixels outside of the array bounds have a value of zero.

Implement the blur function to achieve the expected output.

Starter Code:

#include  #include  #include  #include  #include  constexpr size_t SIZE = 20; static void printImage(int data[SIZE][SIZE]); static void blurImage(int data[SIZE][SIZE]); int main() { int image[SIZE][SIZE] = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 0, }, {0, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, }, {0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 99, 0, 0, 0, }, {0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, }, {0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 0, }, {0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, }, {0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, }, {0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, 0, }, {0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, 0, }, {0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 0, 0, 0, }, {0, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, }, {0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 99, 99, 0, 0, 0, 99, 99, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 99, 99, 0, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, }; printImage(image); blurImage(image); printImage(image); } static void printImage(int data[SIZE][SIZE]) { for (auto i = 0; i < SIZE; i++) { for (auto j = 0; j < SIZE; j++) { std::cout << std::setw(3) << data[i][j]; } std::cout << " "; } } static void blurImage(int data[SIZE][SIZE]) { // TODO: implement blur algorithm } 

Expected Output:

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 99 99 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 99 99 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 99 99 0 0 0 0 0 99 99 0 0 0 0 0 0 99 0 0 0 0 99 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 99 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 99 99 0 0 0 99 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 99 99 99 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 19 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 39 39 59 39 39 19 0 0 0 0 0 0 0 0 0 0 0 19 39 39 39 39 19 39 39 39 39 19 0 0 0 0 0 0 0 0 39 59 39 39 19 0 0 0 19 39 39 39 39 19 0 0 0 0 0 39 59 59 39 0 0 0 0 19 0 0 19 39 59 39 19 0 0 0 39 59 59 39 0 0 0 0 19 19 19 0 0 39 39 39 0 0 0 19 59 59 39 0 0 0 0 0 0 19 0 0 39 19 39 0 0 0 0 19 59 39 0 0 0 0 0 0 0 0 0 39 19 39 0 0 0 0 0 19 59 19 0 0 0 0 0 0 0 0 39 19 39 0 0 0 0 0 0 19 59 19 0 0 0 0 0 0 0 19 19 59 0 0 0 0 0 0 0 19 59 19 0 0 0 0 0 0 0 0 39 19 39 0 0 0 0 0 0 19 39 39 0 0 0 0 0 0 0 0 0 39 19 39 0 0 0 0 0 0 39 39 39 0 0 0 0 0 0 0 0 0 39 19 39 0 0 0 0 0 19 59 59 39 0 0 0 0 0 0 0 0 0 39 39 39 0 0 0 0 0 39 59 59 39 0 0 0 0 0 0 0 19 39 59 39 19 0 0 0 0 0 39 59 39 39 19 0 0 0 19 39 39 39 39 19 0 0 0 0 0 0 0 19 39 39 39 39 19 39 39 39 39 19 0 0 0 0 0 0 0 0 0 0 0 19 39 39 59 39 39 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 19 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Evaluate each of the following, accurate to the nearest cent.

Answered: 1 week ago

Question

7. Understand the challenges of multilingualism.

Answered: 1 week ago