This project provides a method to deconvolve an image, given the kernel.
This functionality is achieved by transitioning the kernel and the image into the Fourier Domain and performing a simplified deconvolution there.
Navigate to the root of the project on your command line and install the dependencies with pip. It's recommended that you create a virtual environment before proceeding.
Python 3.5 or greater is required to run this project
pip install -r requirements.txt
To begin, you'll need an image to deconvolve and a binary or grayscale image of the kernel that convolved the image. On your command line, execute the reconstruct.py
file with Python and specify the kernel and image to deconvolve.
python reconstruct.py KERNEL_IMAGE_PATH IMAGE_PATH
A more advanced example usage follows below. This can also be executed as a test or demo, as the example files used are provided with this project.
python reconstruct.py "./example/disks/disk_1.png" "./example/data/Routine1008.std" -m 0.487 -x -750 -c -0.000015
This project provides functionality to optimize for the size of the kernel. This is useful if the general structure of the kernel is known but the relative size used to convolve the image is not.
The optimize_magnification.py
file iterates over a range of magnifications, optimizing for generated noise parameter. After iteration finishes, the best deconvolution is saved and the best magnification is printed. Basic use follows:
python optimize_magnification.py KERNEL_IMAGE_PATH IMAGE_PATH
A more advanced, demo example follows:
python optimize_magnification.py "./example/disks/disk_2.png" "./example/data/Routine95120.std" -i 40 -s 0.3 -e 0.4
save_magnifications.py
provides the functionality to save all deconvolutions within a range of magnification values. This can be useful in determining the correct magnification if the optimization procedure achieves an undesirable value.
Basic example use:
python save_magnifications.py KERNEL_IMAGE_PATH IMAGE_PATH
save_raw_image.py
provides the functionality to save binary images generated by CR plates as regular JPEGs.
Example use:
python save_raw_image.py BINARY_IMAGE_PATH IMAGE_WIDTH IMAGE_HEIGHT
Each of the python files above provides further documentation for their use over the command line. To print out the documentation, type -h
as an argument.
Example:
python reconstruct.py -h
Which prints out:
usage: reconstruct.py [-h] [-m MAGNIFICATION] [-dw DETECTOR_WIDTH] [-dh DETECTOR_HEIGHT] [-c CORRECT_DISTORTION] [-x SHIFT_X] [-y SHIFT_Y] disk_image_path detector_image_path
positional arguments:
disk_image_path The path to the disk image used to deconvolve the detector image.
detector_image_path The path to the detector image to be deconvolved.
optional arguments:
-h, --help show this help message and exit
-m MAGNIFICATION, --magnification MAGNIFICATION
How much the disk should be magnificed. Defaults to 1.0.
-dw DETECTOR_WIDTH, --detector_width DETECTOR_WIDTH
The width of a raw, binary detector image, if a binary detector image is specified.
-dh DETECTOR_HEIGHT, --detector_height DETECTOR_HEIGHT
The height of a raw, binary detector image, if a binary detector image is specified.
-c CORRECT_DISTORTION, --correct_distortion CORRECT_DISTORTION
Specifies if distortion correction should be applied. A good starting number for this is -1.5e-5.
-x SHIFT_X, --shift_x SHIFT_X
How much to shift the detector image left or right. Shifting the image will delete the portion of the image shifted. The remainder will be filled with black.
-y SHIFT_Y, --shift_y SHIFT_Y
How much to shift the detector image up or down. Shifting the image will delete the portion of the image shifted. The remainder will be filled with black.
A special thanks goes out to:
-
Dr. Thorarin Bjarnason and Dr. Holzman who supervised this project and provided guidance while in development.
-
The UBC MURPH Initiative, who provided funding for this project.
-
The Interior Health Authority of British Columbia, who provided access to equipment necessary for this project's development.