Assignment 1 Solution

1.    ) Write a program to create a pgm le with 8x8 checkerboard pattern. Image dimensions will be 800x800 pixels and each black and white cell will be 100x100 pixels. Consider the following gure for details. In the gure B denotes black cells and W denotes white cells.

 

800



 

100       100                                 100



 

100     B          W      W

 

100          W

 

 

800



 

 

 

 

100          W      B

 

 

 

Figure 1: Checkerboard

 

PGM     le format is as follows

 

P2

 

Width Height

 

MaxGray

 

Data

 

Width and height are width and height of the image. MaxGray is the maximum gray value. This will be 255 in our case. Data is grayscale pixel values (0 for black, 255 for white) separated by space. When your program produces the pgm les, you can use gpicview or gimp to open pgm les on machines running Linux. Use pgm extension for your les.



 

Sample pgm     le is given below

 

P2

 

7   5

 

255

 

255 255 255 255 255 255 255

 

200 200 200 200 200 200 200

 

150 150 150 150 150 150 150

 

100 100 100 100 100 100 100

 

50 50 50 50 50 50 50

 

Submit your program electronically using the blackboard system

 

The program you submit should be your own work. Cheating will be reported to office of academic integrity.

 

Both the copier and copiee will be held responsible.
Powered by