A colony picker is an instrument that is used to automatically localize, pick up or duplicate microbial colonies that grow on a fixed or fluid medium. Usually, a Petri dish is inserted on the light plate of the colony picker, after which algorithms for image analysis choose the right colonies and a operate a robot arm to sample those colonies. Such appliances are used in both research laboratories and industrial surroundings, e.g. to analyze food or blood samples.

koloniepikker Victoria amazonica

The image processing software sees the photo of the Petri dish in the format of a bitmap. This is nothing but a rectangle grid of which the boxes are called bits because they can only take two forms. Every bit of the grid is either empty (represented by a space) or covered by a colony (represented by a hash: #). As an example you can see a bitmap below on which a number of colonies can be seen. In a bitmap, a colony is formed by an area of neighbouring covered bits. Bits are here called neighbouring if they have a side in common. However, the software will never see an area of neighbouring covered bits as a colony, if it contains bits on the outer rim of the bitmap.

bitmap van een petriplaat

Assignment

Define a class Petridish which can be used to analyze colonies on a Petri dish. the objects of this class must contain at least the following methods:

Example

In the example session below we assume that the text file dish.txt is situated in the current directory. This file contains the bitmap of a Petri dish that was graphically shown above.

>>> dish = Petridish('dish.txt')
>>> print(dish)
<BLANKLINE>
                         ###                                
                         #####                              
                         #######                            
                        #######                             
                         ######                             
                         ###### ##                          
                         ####  #####                        
                           ## ######        ####            
                        #    ######       ####              
                      ###  ##########    #####              
                    #######  ####  ##   ######              
                    ######### ##   #      #####             
          #           ####   ###          ###               
         #####        ####    #     ##     ##               
         #####                    ######    #               
        ######                   ########                   
         ####                     ########                  
                                  #######                   
                                  #######                   
>>> dish.colony(10, 35)
42
>>> print(dish)
<BLANKLINE>
                         ###                                
                         #####                              
                         #######                            
                        #######                             
                         ######                             
                         ###### ..                          
                         ####  .....                        
                           ## ......        ####            
                        #    ......       ####              
                      ###  ..........    #####              
                    #######  ....  ..   ######              
                    ######### ..   .      #####             
          #           ####   ...          ###               
         #####        ####    .     ##     ##               
         #####                    ######    #               
        ######                   ########                   
         ####                     ########                  
                                  #######                   
                                  #######                   
>>> dish.colony(10, 40)
Traceback (most recent call last):
AssertionError: no colony was found on position (10, 40)
>>> dish.colony(10, 45)
30
>>> print(dish)
<BLANKLINE>
                         ###                                
                         #####                              
                         #######                            
                        #######                             
                         ######                             
                         ###### ..                          
                         ####  .....                        
                           ## ......        ....            
                        #    ......       ....              
                      ###  ..........    .....              
                    #######  ....  ..   ......              
                    ######### ..   .      .....             
          #           ####   ...          ...               
         #####        ####    .     ##     ..               
         #####                    ######    .               
        ######                   ########                   
         ####                     ########                  
                                  #######                   
                                  #######                   
>>> dish.undo()
>>> print(dish)
<BLANKLINE>
                         ###                                
                         #####                              
                         #######                            
                        #######                             
                         ######                             
                         ###### ##                          
                         ####  #####                        
                           ## ######        ####            
                        #    ######       ####              
                      ###  ##########    #####              
                    #######  ####  ##   ######              
                    ######### ##   #      #####             
          #           ####   ###          ###               
         #####        ####    #     ##     ##               
         #####                    ######    #               
        ######                   ########                   
         ####                     ########                  
                                  #######                   
                                  #######                   
>>> dish.colonies()
5
>>> dish.colonysize()
32.2