Skip to content

Commit f9b266b

Browse files
committed
Add new methods published on JOSR, fisheye calibration methods
1 parent 05b026c commit f9b266b

38 files changed

+1652
-227
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
![Coverage](https://github.com/DiamondLightSource/discorpy/raw/master/docs/coverage_report/coverage.svg)
1515

1616

17-
**Discorpy** is an open-source Python package designed for camera calibration and distortion
18-
correction with sub-pixel accuracy. It calculates parameters of correction models
19-
using a grid pattern image. Primarily, the package implements methods published in
20-
[Optics Express](https://doi.org/10.1364/OE.23.032859) and offers a comprehensive
21-
pipeline for data processing. Starting from version 1.4, the package also includes
22-
perspective distortion correction capabilities.
17+
**Discorpy** is an open-source Python package implementing methods for calibrating and correcting distortion
18+
in lens-based imaging systems ([1](https://doi.org/10.1364/OE.23.032859), [2](https://doi.org/10.1107/S1600577525002267)).
19+
Unlike existing approaches that require multiple calibration images or iterative optimization,
20+
Discorpy and its algorithms can independently characterize both radial and perspective distortion
21+
with high accuracy across a wide range of distortion strengths—using only a single calibration image
22+
and direct computation. This makes the software a practical tool for a wide range of imaging applications.
2323

2424
**Author and maintainer:** Nghia Vo, *NSLS-II, Brookhaven National Laboratory, US; Diamond Light Source, UK.*
2525

@@ -105,6 +105,10 @@ Demonstrations
105105

106106
![webcam_after](https://github.com/DiamondLightSource/discorpy/raw/master/data/demo/checkboard_after.jpg)
107107

108+
- Calibrate a fisheye camera (GoPro Hero-8).
109+
110+
![GoPro_Hero8](./data/demo/fisheye_calibration.jpg)
111+
108112
- Apply to a hazard camera of the [Mars Perseverance Rover](https://mars.nasa.gov/mars2020/multimedia/raw-images/).
109113
Details of how to estimate distortion coefficients of that camera without using
110114
a calibration target are shown [here](https://discorpy.readthedocs.io/en/latest/usage/demo_08.html).

data/demo/fisheye_calibration.jpg

476 KB
Loading
4.26 MB
Loading
4.6 MB
Loading

discorpy/losa/loadersaver.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- Load data from an image file (tif, png, jpg) or a hdf file.
2828
- Save a 2D array as a tif/png/jpg image or a 2D, 3D array to a hdf file.
2929
- Save a plot of data points to an image.
30-
- Save/load metadata to/from a text file.
30+
- Save/load metadata to/from a text/json file.
3131
- Save/load python list
3232
3333
"""
@@ -453,23 +453,23 @@ def save_image(file_path, mat, overwrite=True):
453453
def save_plot_image(file_path, list_lines, height, width, overwrite=True,
454454
dpi=100):
455455
"""
456-
Save the plot of dot-centroids to an image. Useful to check if the dots
457-
are arranged properly where dots on the same line having the same color.
456+
Save the plot of points to an image. Useful to check if the points are
457+
arranged properly where points on the same line having the same color.
458458
459459
Parameters
460460
----------
461461
file_path : str
462462
Output file path.
463463
list_lines : list of array_like
464-
List of 2D arrays. Each list is the coordinates of dots on a line.
464+
List of 2D arrays. Each list is the coordinates of points on a line.
465465
height : int
466466
Height of the image.
467467
width : int
468468
Width of the image.
469469
overwrite : bool, optional
470470
Overwrite the existing file if True.
471471
dpi : int, optional
472-
The resolution in dots per inch.
472+
The resolution in points per inch.
473473
474474
Returns
475475
-------
@@ -529,15 +529,15 @@ def save_residual_plot(file_path, list_data, height, width, overwrite=True,
529529
file_path : str
530530
Output file path.
531531
list_data : array_like
532-
2D array. List of [residual, radius] of each dot.
532+
2D array. List of [residual, radius] of each point.
533533
height : int
534534
Height of the output image.
535535
width : int
536536
Width of the output image.
537537
overwrite : bool, optional
538538
Overwrite the existing file if True.
539539
dpi : int, optional
540-
The resolution in dots per inch.
540+
The resolution in points per inch.
541541
font_family : str, optional
542542
To set the font family
543543
@@ -659,8 +659,8 @@ def open_hdf_stream(file_path, data_shape, key_path='entry/data',
659659
def save_plot_points(file_path, list_points, height, width, overwrite=True,
660660
dpi=100, marker="o", color="blue"):
661661
"""
662-
Save the plot of dot-centroids to an image. Useful to check if the dots
663-
are arranged properly where dots on the same line having the same color.
662+
Save the plot of points to an image. Useful to check if the points are
663+
arranged properly where points on the same line having the same color.
664664
665665
Parameters
666666
----------
@@ -675,7 +675,7 @@ def save_plot_points(file_path, list_points, height, width, overwrite=True,
675675
overwrite : bool, optional
676676
Overwrite the existing file if True.
677677
dpi : int, optional
678-
The resolution in dots per inch.
678+
The resolution in points per inch.
679679
marker : str
680680
Plot marker. Full list is at:
681681
https://matplotlib.org/stable/api/markers_api.html
@@ -777,11 +777,10 @@ def load_metadata_txt(file_path):
777777

778778

779779
def __numpy_encoder(obj):
780-
if isinstance(obj, (np.int_, np.intc, np.intp, np.int8,
781-
np.int16, np.int32, np.int64, np.uint8,
782-
np.uint16, np.uint32, np.uint64)):
780+
if isinstance(obj, (np.int8, np.int16, np.int32, np.int64,
781+
np.uint8, np.uint16, np.uint32, np.uint64)):
783782
return int(obj)
784-
elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)):
783+
elif isinstance(obj, (np.float16, np.float32, np.float64)):
785784
return float(obj)
786785
elif isinstance(obj, (np.ndarray,)):
787786
return obj.tolist()
@@ -895,3 +894,24 @@ def save_python_list(file_path, python_list, overwrite=True):
895894
with open(file_path, 'wb') as f:
896895
pickle.dump(python_list, f)
897896
return file_path
897+
898+
899+
def find_file(path):
900+
"""
901+
Search file
902+
903+
Parameters
904+
----------
905+
path : str
906+
Path and pattern to find files.
907+
908+
Returns
909+
-------
910+
str or list of str
911+
List of files.
912+
"""
913+
path = __correct_path(path)
914+
file_paths = list(path.parent.glob(path.name))
915+
if not file_paths:
916+
raise FileNotFoundError(f"No files found matching: {path}")
917+
return sorted([file.as_posix() for file in file_paths])

discorpy/post/postprocessing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ def _generate_perspective_map(mat, list_coef):
462462
def correct_perspective_image(mat, list_coef, order=1, mode="reflect",
463463
map_index=None):
464464
"""
465+
Apply perspective correction to an image.
465466
466467
Parameters
467468
----------

0 commit comments

Comments
 (0)