Python class for Image Processing and Gamma Ray detection using OpenCV, PIL and NumPy libraries
gamma-ray-detection detects the high energy values when a CMOS sensor and a 10x10 matrix of collimated scintillator crystals are exposed to a radioactive source that emits gamma-ray beams. The camera and the scintillator are inside of a light-trap black box (gamma camera).
Two python classes have been developed:
It is highly recomomended to run the training scrips inside of python environment, in case the system does not have any use the following procedure (check Virtualenvwrapper Installation for more details).
$ pip install --user virtualenvwrapper virtualenv
Add three lines to your shell startup file (.bashrc, .profile, etc.) to set the location where the virtual environments should live:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
After editing it, reload the startup file (e.g., run source ~/.bashrc
) and create a python environment:
$ mkvirtualenv venv_py
$ workon venv_py
Once the python environment was configured, run the following procedure to install all the required packages
(venv_py)$ git clone https://github.com/ahestevenz/gamma-ray-detection
(venv_py)$ cd gamma-ray-detection
(venv_py)$ pip install -r requirements.txt
First, the equipment (camera + 10x10 matrix scintillator crystals) must be calibrated with the setCalibrationGrid.py script. In this stage images with the following features are used:
ahestevenz@columbia:~/IP/work/gamma-ray-detection$ python setCalibrationGrid.py -h
usage: setCalibrationGrid.py [-h] -d DIRECTORY -b BACKGROUND -i INDEX
[-m FRAME] [-f FILE_CALIB] [-s] [-v] [-w]
optional arguments:
-h, --help show this help message and exit
-d DIRECTORY, --directory DIRECTORY
path to directory of images acquire with the calibration
set
-b BACKGROUND, --background BACKGROUND
path to directory of images acquire in background
-i INDEX, --index INDEX
image index for the image processing in the directory
-m FRAME, --frame FRAME
frame of the image selected, the default value is 0
-f FILE_CALIB, --file_calib FILE_CALIB
calibration file location
-s, --show show graphics
-v, --verbose verbose mode
-w, --write_images save images
Then, the size of the scintillator crystal is obtained as follows,
Threshold detects a square
Corrected Shape
| x | y | width | height |
| 400 | 304 | 516 | 536 |
![]() |
![]() |
![]() |
---|---|---|
Edge Detection | Mask | Grid |
Then superpixels (10x10 crystals matrix) are carried out by the getCentroids.py script. Here, images with following features are used:
ahestevenz@columbia:~/IP/work/gamma-ray-detection$ python getCentroids.py -h
usage: getCentroids.py [-h] -r RADIOACTIVE_SOURCE -b BACKGROUND -i INDEX
[-m FRAME] [-f FILE_CALIB] [-s] [-v] [-w]
optional arguments:
-h, --help show this help message and exit
-r RADIOACTIVE_SOURCE, --radioactive_source RADIOACTIVE_SOURCE
path to essay directory of images acquire with
the radioactive sources
-b BACKGROUND, --background BACKGROUND
path to essay directory of images acquire in
background
-i INDEX, --index INDEX
image index for the image processing in the essay
directory
-m FRAME, --frame FRAME
frame of the image selected, the default value is 0
-f FILE_CALIB, --file_calib FILE_CALIB
calibration file location
-s, --show show graphics
-v, --verbose verbose mode
-w, --write_images save images
The results from getCentroids.py is a cualitative pcolor graph with the grid of superpixels, as we can observe below,
![]() |
![]() |
---|---|
Radioactive sources location (*) | Results |
![]() |
![]() |
---|---|
Radioactive sources location (*) | Results |
(*) Note: The picture appear mirrored respect to the results