This repository is for the bachelor thesis Automated Pre-Processing of Cell Culture Image Datasets for Machine Learning written by Richard Piekara. The goal was to establish an automated pre-processing procedure of cell culture images for future frame prediction algorithms such as FutureGAN. The cell culture images were brightfield images of pancreatic ductal adenocarcinoma (PDAC) cells and are initially a Leica Image File (LIF). The procedure is adjusted to this but is modifiable to be used for other cells or image types.
The scripts folder contains all Python scripts for the pre-processing. The imageviewer folder is a submodule. It is the imageviewer repository which is used to display the cell images on the graphical user interface (gui). The imageviewer repository is a slightly modified version of the PythonImageViewer repository by Akita.
The procedure consist of six consecutive steps:
- Import
- Registration
- Crop
- Split
- Segmentation
- Export
For a more detailed description take a look at the bachelor thesis.
There are two types of scripts:
- scripts which starts automatically (referred to as auto scripts)
- Registration.py
- Segmentation.py
- Export.py
- scripts with a gui (referred to as gui scripts))
- Import.py
- CropAndSplit.py
Auto scripts use ScriptBase.py to function correctly. WindowsBase.py is an expansion of ScriptBase.py used by the gui script to function correctly. ScriptBase.py and WindowsBase.py contain general functions used by the scripts. Gui scripts use additionally imageviewer.py to display images on the gui.
To use the scripts download the repository. Additionally download the files of the submodule repository imageviewer and place the files in the imageviewer folder. Alternatively clone the repository including the submodule with the following command:
git clone --recurse-submodules https://github.com/rpieki/cell-image-pre-processing
The scripts can be started via the Terminal or Windows PowerShell.
The procedure scripts concantenates all six steps and automatically executes them successively. All images are saved alongside the LIF file. Multiple LIF files can be processed at once by choosing the correct Procedure file.
The single step scripts can be used on their own or single steps can be commented out in the Procedure files.
Import.py is a gui script. Input is a LIF file which is read. If no filepath is provided a filedialog is opened. All images contained in the LIF file are listed. Multi-frame can be added to the upper list. Multi-tile images cannot be saved. Additionally the images can be renamed. The chosen images are saved as TIF images using multithreading by pressing the button.
root = tk.Tk() # create tkinter instance
app = ImportLif(master=root, filepath=None) # initialize script
app.mainloop()
For the rest of the scripts input is a TIF or JPEG image or a txt file containing a filepath to an image in every line. If no filepath is given a filedialog is opened to choose an image or a txt file.
Registration.py is an auto scrip and applies registration to multi-frame images using multiprocessing. The registration is started by a second command defining the used registration transformation.
app = Registration() # initialize script
app.registration(app.rigid_body, max_workers=None) # choose registration transformation
The available transformation rigid_body which applies a rigid body transformation to a multi-frame image. As reference serves the previous already registered image. max_workers defines the simultaneously running processes. Default is None which uses the number of logical cores. It is recommended to keep the number low as registration uses a high amount of memory.
CropAndSplit.py is gui script which crops the multi-frame images to square images. Then it cuts the images into smaller squares. The small images are saved in folders with all their corresponding time frames. Four values can be entered to define the cropping and cutting. Number of patches for each row and column defines the number of small images in every row and column which must the same. Next is the size of the small images. Only one "small" image can be chosen to crop manually and perform no cutting. Additionally the x and y pixel position of the square on the uncropped image must be provided.
root = tk.Tk() # create tkinter instance
app = CropAndCut(master=root) # initialize script
app.mainloop()
Segmentation.py is an auto scrip and applies segmentation (binary image) to multi-frame images using multiprocessing. The segmentation is started by a second command defining the used segmentation algorithm.
app = Segmentation() # initialize script
app.segmentation(algorithm=app.brightfield_pdac_cells) # choose segmentation algorithm
The available algorithm applies binary segmentation to the image and is adjusted to the brightfield PDAC cells. After segmentation cells have the pixel intensity 1 (white) and the background have 0 (black).
Export.py an auto script and saves multi-frame images into folders as single JPEGs using multithreading. Other formats are possible.
app = Export() # initialize script
app.export() # start export