Superresolution Microscopy Research Practicum¶
- authors
- Bernd Rieger, b.rieger@tudelft.nl, room: F266
- Ronald Ligteringen, r.ligteringen@tudelft.nl, room: F261
- date: April 3, 2020
Introduction¶
As a result of the COVID-19 virus in March 2020 this Research Practicum (RP) has been converted from an onsite lab to a home lab. This means that all work can and should be done from home with your laptop or desktop and a smartphone-camera or movie-camera. The camera is used to record images shown on your computer. The recorded video must be uploaded to your computer where you will write a Python program to process the video. This program together with the results and a report are the final deliveries for this RP.
This manual will help you install and use the python programming environment and the python script used in this practicum to display the images. Furthermore a few pointers are given on how to use the DIPlib image processing package for python.
In the Python manual a very short introduction is given to different aspects of the python environment used in this practicum. Note this manual does not provide a course about python!
Packages typically used in this practical are PyDIP
, numpy
, matplotlib
, ipywidgets
and cv2
(a.k.a. opencv
). To learn about these packages look at the websites given below and check their usage in the show_movies.py
script provided in this practicum.
- http://www.numpy.org/
- https://matplotlib.org/
- https://ipywidgets.readthedocs.io/en/stable/
- https://opencv-python-tutroals.readthedocs.io/
The PyDIP
package will be used to do all the image processing in this practical. It is part of DIPlib library for quantitative image analysis developed in our research group Quantitative Imaging. In chapter PyDIP package some of the functions available in PyDIP
and necessary for this practical are described.
PyDIP package¶
The purpose of this practical is to write a program to find locations of the different blobs you see in each time frame. These frames can be shown and recorded with show_movies
and capture_movies
. The file-format of the recorded image timeseries is ICS. This is the preferred format used in DIPlib: https://svi-opensource.github.io/libics/.
Below some recommendations are provided that can help you solve this task:
- use the DIPlib library with the python package PyDIP. Follow the installation instructions in the DIPlib manual to install this package on your computer
Note
These instructions are currently only provided for Windows.
import PyDIP as dip
- almost all functions available in DIPlib can be used via PyDIP. A description of these functions can be found here: https://diplib.github.io/diplib-docs/. You can also find a (sometimes very brief) description via the
help
function in python:
help(dip)
- bring in the recorded images with
dip.ImageReadICS()
:
imgs = dip.ImageReadICS('C:/rp/diplib/images/chromo3d.ics')
Note
IPython (Jupyter) allows for autocompletion with the [TAB] key! Also note the use of forward-slashes /
in the filename.
- typically noise suppression can be done with the function
dip.Gauss()
. Use smoothing parameters like[2, 2, 0]
. Note the zero as you do not want to smooth along the time axis. - use a
for
-loop to iterate over all time frames of the recorded image timeseries - the
dip.IsodataThreshold()
anddip.Label()
functions can be used to segment the blobs from the background: - to find the center of mass of the blobs you can use the function
dip.MeasurementTool.Measure()
together with a mask image (from the threshold) and the original intensity image. This very importantMeasure
function also allows you to find the size of objects - make use of that - you can store the found coordinates into an array for each time frame and add additional coordinates in the loop
- after you have localized all blobs and stored them in an array you can use the following snippet to generate an image from these coordinates:
reconstruct = dip.Image(sizes=[640, 480], dt='SFLOAT')
reconstruct.Fill(0)
for ii in coordinates:
reconstruct[round(ii[0]), round(ii[1])] += 1
Some useful functions:
Sizes()
, Squeeze()
, Fill()
, Sum()
, Overlay()
, ContrastStretch()
, Show()
Setting up the practicum¶
For this practicum you will display a sequence of images on your computerscreen and record those images with your camera. This recorded video will then be processed with your Python script using PyDIP functions.
To display the image sequence you need to download the following:
-
download all images by clicking on this link: ftp://qiftp.tudelft.nl/rp/Movies.zip
Warning
This is a large file (8.4GB), make sure you have enough space on your computers disk and enough time to wait for the download to complete!
Tip
You can also use FileZilla, fill in the hostname
qiftp.tudelft.nl
and clickQuickconnect
. In the right upper window click therp
directory, right-click in the right lower window on the fileMovies.zip
and selectDownload
. -
unzip
Movies.zip
and make note of the location of the resultingMovies
directory (the full path) - download the Python scripts needed to display the image sequence by clicking on this link: https://gitlab.tudelft.nl/rligteringen/rp_sm/-/archive/master/rp_sm-master.zip
- unzip
rp_sm-master.zip
in your working directory (i.e. the directory where you will be developing your scripts for this practicum)
Warning
The following instructions have not yet been rewritten for working from home!
- after logging in with your netid go the the directory
c:\Users\<netid>
and create the directoryrp
. In this location you will store your programs and data - copy all
ipynb
- andpy
-files fromC:\rp\
toc:\Users\<netid>\rp\
. These scripts can be used to show all images and record videos with the webcam. Do not copy thediplib
andMovies
directories! - start Jupyter via
Start Menu -> Anaconda3 -> Jupyter Notebook
- after the notebook-webpage has opened navigate to your
rp
directory in the filemanager - execute both the
show_movies.ipynb
notebook and thecapture_movies.ipynb
notebook to create your datafiles (movies)- check the code in both notebooks and adjust to your needs
- check the key-commands for recording movies
- After pressing the ‘s’-key (save) in
capture_movies.ipynb
wait for the ‘Saving…’ message at the bottom of the window to disappear before closing the window otherwise the saved file will be corrupt! Note that during the save-operation the window title might show ‘(Not responding)’. Please disregard this message and wait for the save-operation to finish. - note that both notebooks actually call python scripts. These scripts can also be started directly from the command line but need some small modifications to allow for parameters. To execute these scripts start
Start Menu -> Anaconda3 -> Anaconda Prompt
and for instance enterpython show_movies_anim.py
- create a new notebook to write your own program or use the Spyder IDE via
Start Menu -> Anaconda3 -> Spyder
Finally, this is an open Research Practicum in the sense that you can decide for yourself on how to solve the problem. You do not need to use the given scripts. They can also be viewed as examples on how to develop your own solution!
Using the DIPlib viewer¶
There are two ways to show images in PyDIP. The easiest way is to call the Show()
method for any dipimage
-object
imgs.Show()
Note: the chromo3d.ics
file contains 16 frames and the Show()
method squeezes and stretches these frames
It is also possible to start the DIPlib viewer. For this you can use the following snippet
dip.viewer.Show(imgs)
dip.viewer.Spin()
Note: always call the Spin()
function after Show()
and always close the viewer window with [CTRL]-w
Make sure you learn the different aspects of this viewer via this website: https://diplib.github.io/diplib-docs/group__viewer.html