I'm not sure its supposed to be as difficult as you say. This is an introductory level course.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int nrows = 5; // Number of Image rows
const int ncolms = 5; // Number of Image columns
int picture[nrows][ncolms]; // Array to hold an images pixel data.
char location[50]; // File name inputed by user.
ofstream outData;
int i; // Array subscript.
int j; // Array subscript.
cout << "What is the name of the input file? "; // File path is entered
cin >> location;
ifstream in_data(location, ios::in); // Opens file
if(!in_data) { // Error message and exit if file doesn't exist.
cerr <<"File could not be opened\n";
exit(1);
}
for(i = 0; i < nrows; i++) // Inputs data into array
{
for(j = 0; j < ncolms; j++)
{
in_data >> picture[i][j];
}
}
cout << "Now write the file under new name" << endl;
cout << "Enter File path and name: "; // User enters location and name of enhanced image.
cin >> location;
outData.open(location); // Enhanced picture file is created
for(i = 0; i < nrows; i++) // Writes data to file.
{
for(j = 0; j < ncolms; j++)
{
outData << picture[i][j] << " ";
}
outData << endl;
}
cout << endl << "..FILE SAVED.." << endl << endl;
return 0;
}
|
This is what we were given to start with, however I'm still really confused.
In the description our professor gave us these hints as to how to write up a function for both noise reduction and edge definition.
Noise Reduction - Reducing noise in a picture requires two steps. The first step is to determine whether the value in a particular location or pixel is noise. The second is to replace the noise with something more meaningful. In this problem, each pixel will contain a value from 0 to 9. A value will be considered noise if it differs from all eight of its neighbors by more than a cutoff value. To replace the noisy value, you should take the average (rounded to the nearest int) of all the neighbors and use the result to replace the original value. The cutoff value should be an argument to the noise reduction function
Edge Definition - To increase the contrast requires lumping values which are close in intensity and replacing all these values with a single value. For example, you might replace {0, 1, 2} with 1, {3, 4, 5} with 4 and {6, 7, 8, 9} with 8.
The program should be menu oriented like so.
Please select an option
1) Process new image
2) Write enhanced image to file
3) Display enhanced image on screen
4) Exit Program
Rinse and Repeat
I hope that clears it up for you, because it didn't for me. I'm stumped