


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



ECS 102 Lab 19 Spring 2009 Name ________________________ Section 1(3:45) 2(12:45) Anywhere that I ask you to observe what happens, write down your observations in the space provided. Working with pictures, 2 dimensional array. I. Open the file picture1.txt. Notice that it has two numbers on the first line, and a whole lot of numbers underneath. A) Without driving yourself nuts, make some observations about the numbers, EXCLUDING THOSE FIRST TWO NUMBERS.
fscanf(infile,"%d%d", &numcols, &numrows); printf("number of rows %d\n number of columns %d", numrows,numcols); /*To read in the picture data, we will read across the first row, one column (number) at a time, then across the second row, and so on, for the right number of rows. / for (r=0; r<numrows; r++) { for (c=0; c<numcols; c++) fscanf(infile,"%d", &raw[r][c]); } / The picture is in gray scale, with 0 representing white and 255 representing black. We will convert it to black and white, first evenly, that is, anything below or equal to 255/2 will be white and anything above will be black. The character ' ' (a space) will be white, and the character 'M' will be black. / / Here we are NOT printing the picture to a file, just setting up the array with the picture. / for (r=0; r<numrows; r++) { for (c=0; c<numcols; c++) { if (raw[r][c]>255/2) pic[r][c]='M'; else pic[r][c]=' '; } / end for c / } / end for r / / Print the picture, one row at a time, going column to column, printing to file characters, not separated by spaces, but with a newline at the end of each row. */ for (r=0; r<numrows; r++) { for (c=0; c<numcols; c++) fprintf(outfile,"%c", pic[r][c]); fprintf(outfile,"\n");
What does a low number represent? a high number? B) Store a copy of the file picture1.txt in the project folder so the program can find it. C) Run the program. On the console window you can see how many rows and columns there are. Number of rows: Number of columns: Open the output file, picture1out.txt. Change the font to a fixed width font, and set the size to 3 or 4 (or smaller). Open the window wide so you can see the right hand edge (it should be pretty smooth.) If you look in the middle, you may be able to see the picture. It is a little elongated because characters, unlike pixels, are taller than they are wide (including the space between lines). D) Since fixed width characters are about twice as tall as they are wide, modify the print section of the program so that each character is printed twice. III. Your turn to make the picture better, using photo processing. Some things to try a different cutoff for black and white: maybe everything below 230 counts as white instead of everything below 128. Experiment with different cutoffs. "2 bit" gray scale, ie, 4 colors, maybe using the space, the comma, the o, and the M. Or you pick the characters for different shades of "gray" (black to white ratio). Experiment with different cutoffs. What would the cutoffs be if they were evenly spaced? What cutoff did you like best for the output? What characters did you use? more than 4 shades, with cutoffs of your choice. Print out your code for one nice modification, and print the picture. Make the font (of the picture) small enough so it almost fits on one page, then print one page only.
picture source: http://www.cs.bath.ac.uk/~pjw/Q3D/newroomflower/panda.jpg