Wednesday, 25 April 2018

The Finished Article

Final Version

Title:      Cell Segmentation
Module:  Image Processing - DT021A/4 - Dublin Institute of Technology   
Author:   Safiah Sadeq, Christopher Byrne and James Lowe
Date:       19/04/2018

The final version of the code may be found here

Procedure

First an image of a group of cells is read into the program. A denoising filter is used to smooth out the original image to remove areas of noise. A binary mask is created which outlines what is a cell and what is not a cell. With the areas that are a cell having a value of 255 and background having a value of 0. A watershed algorithm is applied using that mask and the original image which outlines the boundary of all the cells in the image. The user is shown the original image with a set of instructions "Left Click to Segment -- Right Click to Return to Original Image". When the user left clicks on a cell the coordinates of the that mouse click is taken. The coordinates are then used in the watershed algorithm mask to fill from those coordinates to the boundary of the cell. This creates a mask that masks everything but the cell that the user selected and the outline of each of the other cells. This mask  is then applied to the original image and will display the cell and the outline of each other cell. The user can right click to return to the original image or left click on a  different cell to segment that cell. The user may also press escape to exit.

Pseudo code 

....... START
....... ( Read in image )
....... ( Display image )
....... ( Filter image using denoising filter )
....... ( Create mask of cells )
....... ( Apply watershed to get borders )
....... ( While escape is not pressed)
   ....... ( If right mouse button pressed down )
....... ( segment the cell selected )
        ....... ( If left mouse button pressed down )
....... ( Display original image )
....... ( If escape is pressed )
....... ( Close while loop )
....... END

Final Results

The final code is made up 4 functions and are described be:

1. Display(displayImage)

Function:
Display - Displays image with border and instructions     
Pseudo code:        
....... ( Create border around the image )
....... ( Place white text on top border )
....... ( Show image with border  )     
Calls:
none
Called by:
Main , Segment()
Input Parameters: 
displayImage Returns:
none

Figure 1. Displayed Image

2. FilterAndMask(img)

Function:
FilterAndMask - Filters image and creates a mask       

Pseudocode:
....... ( Convert image to greyscale )
....... ( Apply denoising filter) 
....... ( Create mask by thresholding )
....... ( Invert mask  )
....... ( Return mask  )
Calls:
none
Called by:
Main  
Input Parameters:
img
Returns:         
binaryInvert

Figure 2. bineryinvert - mask showing what is cell and what is not after the function filterandmask

3. Watershed(mask,img)

Function:
Watershed - Finds the borders of the cells              

Pseudocode:
....... ( Find definite background area (ie. not a cell) )
....... ( Find definite foreground area (ie. is a cell) )
....... ( Find the unknown area (not sure if cell or background)
....... ( label markers for foreground )
....... ( Apply watershed )
....... ( Set the boundary colour to blue )

Calls:
none

Called by:
Main

Input Parameters:
mask, img

Returns:
watershedimg

Figure 3. watershed 

4. Segment (mask,img)


Function:

Segment - Segments cell from background and other cells           
Pseudocode:
....... ( if left mouse button is pressed down: )
     ....... ( Take blue component of watershed image
and apply binary threshold leaving only boundary )
     ....... ( make copy of binary threshold image )
     ....... ( Using the coordinates of the mouse click fill from that area on the boundary mask until                        boundary is reached leaving a mask with cell of interest and boundaries of the other cells.         ....... ( Apply mask to original image )
     ....... ( Display resulting image )
     ....... ( set pixels in mask to 255 so it can be reused )
....... ( if right mouse button is pressed down: )    
     ....... ( Display original image)
Calls:
Display()
Called by:
Main
Input Parameters: 
event , x , y , flags , param , watershedImg , mask
Returns:
none

Figure 5. Mask after floodfill

Figure 6. Image after applying mask to original image

Final Implementation 


The user is greeted with the image below in figure x

Figure 7. UI initial state

When the user selects a particular cell, that cell is then isolated along with the borders of every other cell so the user knows where to click to view another cell. The figures below show a couple of different cells that are selected.  

Figure 8. UI after sell selection 1

Figure 9. UI after sell selection 2

Figure 10. UI after sell selection 1

When the user right clicks on the image after selecting a cell the original image reappears and segmentation can be done again by left clicking on a cell. The user can leave the program by pressing the escape key.

Problems Encountered

Many issues where faced on the road to a working program. The main problems occurred within the thresholding and filtering aspects of the project. This was dealt with mainly by my colleague. The problem was that holes kept on appearing in the cells which where solved by improving thresholding. This issue can be seen in the version 1 blog post.

Similar Images 

My colleague worked on applying different images to the code and changing threshold values and here are the following results:

Figure 11. Similar image test

Figure 12. Similar image segmentation 1


Figure 13. Similar image segmentation 2

Figure 14. Similar image segmentation 3



No comments:

Post a Comment