Image Processing

I've never worked with it before, and its proving to be quite difficult. We're supposed to construct a program that will read in an image file (text format), enhance it, and write the enhanced image to a different file.

We're supposed to enhance it two ways, by noise reduction and edge definition. Can anyone who has some experience in this kind of thing help me start out? It would be greatly appreciated.

This is the text file we are using
1 5 6 2 9 6 3 2
1 8 4 6 3 8 0 4
4 6 8 3 6 8 9 0
2 4 6 8 3 8 0 3
4 6 8 7 9 5 2 1
Last edited on
Enhance it? Is this C++SI?
Okay, sorry. That was terible.

Wow, this one's pretty advanced. What's it doing in the beginners forum?

Do you know anything about applying convolution matrices? If you do, sharpening can be solved in minutes with this kernel:
0 -1 0
-1 5 -1
0 -1 0

As for noise reduction, I'm clueless.

This is a rather weird assignment. What are studying?
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
In "normal" image processing you would do noise reduction by a Gaussian or binomial filter kernel (for "normal" noise; for salt&pepper noise a median filter is used instead). For edge detection you can use Canny's operator, though what you want to do is most likely to create a gradient image. You can use the two Prewitt operators or Robert's operator. However, they have a problem with noise. So best thing might be to use the two Sobel operators, which use a Gaussian filter along the edges and differentiate orthogonal to it (i.e., they smoothen the edge itself while differentiating the image on the position of the edge). Then add the resulting two images (one for x- and one for y-directed edges) and normalize the pixel values.

@Helios:
This is a rather weird assignment.
Er, I had this stuff several semesters in my image processing/computer vision/pattern recognition courses, and we had assignments like this almost weekly... (ok, well, the difficulty /did/ increase somewhat...)
I meant for someone who would be considered a beginner in programming.
Topic archived. No new replies allowed.