# a 2-D array image (Prompt)

• 09-25-2005
amirahasanen1
a 2-D array image (Prompt)
Hi there,
I think my main problem is that I can not fully understand the prompt of the assigned program..
It says that I should choose a character such as '#' for the darkest character '0', and a blank for the brightest character, when reading a 2D array of numbers as every number represents brightness level '9'.. then what should we display for all the numbers between like '5' or '3' or '7' ??
Also I can not get the part about correcting errors because it is not explained enough..

That is the assigned problem Prompt, thank you.
-Amy

Photos taken in space by the Galileo spacecraft are sent back to earth as a stream of numbers. each number represents a level of brightness. A large number represents a high brightness level, and a small number represents a low level. Your job is to take a matrix (a two-dimensional array) of the numbers and print it as a picture.
One approach to generating a picture is to print a dark character (such as #) when the brightness level is low, and to print a light character (such as a blank or a period) when the level is high. Unfortunately, errors in the transmission sometimes occur. Thus, your program should first attempt to find and correct these errors. Assume a value is in error if it differs by more than one from each of its four neighboring values, rounded to the nearest integer.
Example

|*|5 |*|
|4| 2 |5 |
|*|2 |*|

The 2 would be regarded as an error and would be given a corrected value of 5
Note that values on the corners or boundaries of the matrix have to be processed differently than the values on the interior. your program should print an image of the uncorrected picture and then an image of the corrected picture.

Sample Input File:

9897979989998997999688998997
8221211996712212299892171239
7915237789768181981969223198
9822128988971612997679352399
8712329897561231899289232687
9753221622717115837899191299
9712829273212382969829336198
7823271213171723973989123498
9815129966695162798989353297
6632819976793223693779212197
9527238878891372597699391798
6219121967812191292661223129
7976769565997866699798899787
• 09-25-2005
VirtualAce
9 = brightest
0 = lowest

Since you are obviously not working with color or pixels they want you to use characters to represent the intensity levels. The errors in transmission (dumb way to put it if you ask me) can be fixed by a simple average filter or linear filter.

Here is a possible solution that will output a greyscale image:

I leave it to you to sort out the data type conversion issues as well as iterating through the 2D array.

Code:

```float color_coef=current_value/9.0f; unsigned char red=(unsigned char)(255.0f*color_coef); unsigned char green=red; unsigned char blue=red; DWORD finalcolor=RGB(red,green,blue);```

4 way average filter
...1...
2.X.3
...4...

Final value of X = (1+2+3+4+X)/5
or

avg_value=(1+2+3+4)/4
finalX=(X+avg_value)/2

or

avg_value=(1+2+3+4)/4
finalX=LI(X,avg_value,bias);

Linear filter (LI)
value=v1+f1*(v2-v1)

Bi linear filter (BI)
value=v1+f1*(v2-v1)
value2=v3+f1*(v4-v3)
finalvalue=value+f2*(value2-value)
• 09-25-2005
amirahasanen1
Sorry, but we have not studied displaying a greyscale image yet, and I did not understand the code at all, it sounds so advanced for me..

And I did not get the filter thing either..
Am sorry but can you explain it simpler? I do not think I am allowed to use this code because I do not understand it and we have not studied those functions/orders and I do not even know in which library they exist..

Thanks,
-Amy
• 09-25-2005
Enahs
You basically want to read from the array. Then replace the numbers with characters you designate as bright or dark. You need to define 10 diff characters as bright or dark. You are then simply reading from the array, and where there is a 0 output your dark character, 9 your brightest characters.

Try getting that done first, as the assignment says do both corrected and uncorrected. Once you get that, it is just a matter of figuring out how to correct it.

Just take it one step at a time.
• 09-26-2005
amirahasanen1
Well, I have worked on that after discovering that we need to display a bright character if the value is from 0 to 4, and a dark character if the value is from 5 to 9..
So I have generated a code for that.. There is a small problem, the array does not go to fully print the last row.. Here is my code:

Code:

```#include <iostream> #include <fstream.h> int main() { char image[13][28]; char file[10] = "Image.txt"; ifstream source; source.open(file); for(int i=0; i<13; i++) { for(int j=0; j<28; j++) { source.get(image[i][j]); } }   for(int m=0; m<13; m++) { for(int n=0; n<28; n++) { if(image[m][n]>=51 && image[m][n]<58 )         cout<<"#"; else if(image[m][n]>=48 && image[m][n]<51)         cout<<" "; else         cout<<image[m][n]; } } cout<<endl<<endl;   return 0; }```
The following is the input file "Image.txt":

9897979989998997999688998997
8221211996712212299892171239
7915237789768181981969223198
9822128988971612997679352399
8712329897561231899289232687
9753221622717115837899191299
9712829273212382969829336198
7823271213171723973989123498
9815129966695162798989353297
6632819976793223693779212197
9527238878891372597699391798
6219121967812191292661223129
7976769565997866699798899787

I get the following output:
www.geocities.com/amirahasanen1/output.JPG

Thanks,
-Amy
• 09-26-2005
amirahasanen1
Okay, so I think that characters' printing out problem is not that important, I would try to handle it..

Now the main problem is that I can not understand this error part, on what basis did the example correct the number in the middle to be "5"? and when do we know that this number is an error??
The following is the error part as stated in the problem prompt:

Unfortunately, errors in the transmission sometimes occur. Thus, your program should first attempt to find and correct these errors. Assume a value is in error if it differs by more than one from each of its four neighboring values, rounded to the nearest integer.

Example:
--------

|*|5 |*|
|4| 2 |5 |
|*|2 |*|

The 2 would be regarded as an error and would be given a corrected value of 5
Note that values on the corners or boundaries of the matrix have to be processed differently than the values on the interior.
• 09-26-2005
Enahs