1. Engineering
  2. Computer Science
  3. write a program to simulate image processing process an image...

Question: write a program to simulate image processing process an image...

Question details

Write a program to simulate image processing.   

  • Process an image file (blur the image).
  • Print out blurred image on screen.

We will use approach 1 for pixels with less than 8 neightbors:

  • Approach 1: pixels with fewer than 8 neighbors are not processed

You need to add code to ADD #1-2:

  • ADD #1: declaration of function blur. Be sure to add IN/OUT/INOUT comment to each parameter.
  • ADD #2: implementation of function blur

You’re not supposed to modify the given code otherwise (at least 10% penalty).

=================================================================================

image_shell:

#include

#include // std::setw()

//----------------------------------------------

// global declarations

//----------------------------------------------

// max dimension of 2D array

const int MAX_ROW = 100;

const int MAX_COL = 100;

//----------------------------------------------

// function declarations

//----------------------------------------------

// blur an image

// Pre: pic filled with height x width numbers

// Post: pic is blurred using a 3 x 3 predefined weight mask

// ADD CODE #1: function declaration

// END ADD CODE #1

// print an image on screen

void printImage(const int pic[][MAX_COL]/*IN*/, int height/*IN*/, int width/*IN*/);

// Pre: pic filled with height x width numbers

// Post: image printed to screen. The height and width are printed first and then the image file data is printed

//----------------------------------------------

int main()

{

// one image

int image[MAX_ROW][MAX_COL] = {

{ 10, 100, 10, 100, 10, 100 },

{ 10, 300, 10, 300, 10, 300 },

{ 100, 10, 100, 10, 100, 10 },

{ 300, 10, 300, 10, 300, 10 } };

int imgHeight = 4; // height of image

int imgWidth = 6; // width of image

// process the image

blur(image, imgHeight, imgWidth);

printImage(image, imgHeight, imgWidth);

return 0;

} // end main

//----------------------------------------------

// Function Implementation

//----------------------------------------------

// blur an image

// Pre: pic filled with height x width numbers

// Post: pic is blurred using a 3 x 3 predefined weight mask

// ADD CODE #2: implementation of function blur

// END ADD CODE #2

// print an image to output stream obj out

void printImage(const int pic[][MAX_COL]/*IN*/, int height/*IN*/, int width/*IN*/)

{

std::cout << height << ' ' << width << '\n';

for (int row = 0; row < height; row++)

{

for (int col = 0; col < width; col++)

{

std::cout << std::setw(4) << pic[row][col];

}

std::cout << '\n';

}

} // end printImage

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution