CS 397

Assignment 1: Colony Counting

Due 2 October 2007


For this assignment we will be designing an algorithm for counting colonies on an agar plate. The colonies are of different sizes, mostly round, mostly separated on the plate, and reasonably homogeneous in color.


Download the data files from here. Note that some of the images are taken with the agar plate facing down, some with it facing up. You don't need to be able to process both. Pick an orientation and stick with it. On the down-facing plates, the colonies will tend to look flatter than they do on the up-facing places.

You will also want to download the files:

Put the .c file in your lib directory and add it to the list of files in the makefile there. Put the .h file in your include directory. You will also want to add an include statement to your programs to include vision.h in them. Feel free to modify vision.h to incorporate any work that you do.


  1. The colony pictures for this assignment were taken on a red background. Using a suitable thresholding method, separate the colonies from the background. Thresholds on the green and blue channels will likely work well enough. The output of this step should be a binary mask. Represent the mask as an array (image) of unsigned chars. You can write out the mask to a file using the writePGM() function. If you use 0 for the background and 255 for the foreground then you will be able to visualize the mask easily.
  2. Write the following functions. Each should take as an argument an unsigned char array (input image), the number of rows, the number of columns, and an unsigned char array (output image) to hold the output.
    • Grow: executes either 4 or 8 connected growing (your choice). If you want, you can add a parameter to indicate the number of grow operations to execute.
    • Shrink: executes either 4 or 8 connected shrinking (should be the opposite of your choice for growing). If you wish, add a parameter to indicate the number of shrinking operations to execute.
    • Median: executes a median filter on the input image.
  3. Execute some combination of growing, shrinking, and median filtering to try and close up and speckles or holes in your regions and eliminate noise (non-colony foreground areas). Don't worry about getting rid of the boundary of the agar plate.
  4. Execute connected region identification on the mask. This will return both a region map and information about the top N regions (you specify N). The number of regions returned is your first estimate of the number of colonies. Think about whether it will likely be high or low.
  5. Using some simple shape measures or other region characteristics, try and eliminate unlikely colony shapes from consideration. Revise your estimate of the number of regions and print it out. You should also visualize the remaining colony regions by eliminating the unlikely regions from the mask.
  6. Execute a mean shift algorithm in RGB space on all of the pixels still left in the foreground (use the pixel values from the original image for this task). Initialize the mean shift algorithm to the mean of the remaining pixels, then iterate until it stabilizes. This will likely be the color distribution of the colonies. Use a threshold in RGB space based on this analysis to eliminate pixels from the mask that are not likely to be colony pixels. Make sure to visualize your result, and print out a new estimate of the number of colonies.
  7. At this point it may be worth running a shrink/grow/median filter combination again, re-running the connected component labeling, and printing out a final guess.



Follow the writeup instructions to create a web page for your assignment. Send the instructor an email with the code in a zip or tar file along with instructions on how to compile and run it as well as a pointer to the URL for the writeup.