Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock

To implement the blur function in C we need to iterate over each pixel of the image and replace its value with the average of itself and its four neighboring pixels above below left right For pixels a... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!