CS261 - Computer Programming II

Lab Project #4 – Bio Image Analysis

 

PROBLEM: You are to write a program in C++ to recursively count the number of independently defined objects in an image.  The image is to be 20 x 20 squares in size.  Each image element (pixel) is either empty, filled, or an error. 

 

Your program shall read in a text file of images.  Each image shall consist of periods ( . ) indicating “empty”, asterisks ( * ) indicating “filled” and E indicating errors.  You can send output either to a file or the screen, your choice.

 

Objects found are considered to be any contiguous set of “filled” squares (that is, squares that are adjacent horizontally, vertically, or diagonally).  Your program will count the objects, listing the size of each object as it is found and will list the total number of objects found.

 

Your program shall make two “scans” of each image.  The first scan shall ignore the errors and treat them as empty squares.  The second scan will treat the errors as “filled” squares.  After running each scan, compare the results of the two scans by computing the ratio of extra objects added on the second scan and comparing the total size of all the objects in each scan.  Present these ratios to the user as percentages.

 

Example:

. . . . . . . . . . . . . . . . . . . .

. * * . . . . . . . . . . . . . . . . .

. . E * . . . . * . . . . . . . . . . .

. . . . . . . . * * . . . . . . . . . .

. . . . . . . . * * . . . . . . . . . .

. . . . . . . . . * * * . . . . . . . .

. . . . . . . . . . * * . . . . . . . .

. . E E . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

 

Scan 1:

     Objects:      2,

     Volumes:      3 and 10          

     Total Volume: 13

Scan 2:

     Objects:      3,

     Volumes:      4, 2 and 10  

     Total Volume: 16

 

Error Ratios:

Objects: 33 %

Volumes:  19 %

 

DESIGN: The design is to be handed in on hardcopy the date the program is due.  To get full credit, make sure you follow recursive design standards discussed in class.  In your design fully detail your data structures and your recursive algorithm. 

 

IMPLEMENTATION: You should store the image as a two-dimensional array of characters or a two-dimensional array of an enumerated type.  Use a class to define it. It might make it easier if you have several images in the text file for it to go through each time.

 

ASSUMPTIONS:  You may assume that the input is always valid.

 

WHAT TO HAND IN: The design is to be handed in on paper.  The program and sample run should also be on hardcopy.

 

HINTS:  You should be careful that your array subscripts don't ever go out of range and bomb the program.  Recursing forever will quickly bomb the program as well. I suggest that you try a smaller array at first, perhaps only 5 x 5.  Make sure you keep a “good” copy of the image in a seperate variable for the second scan.