-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distortion correction preview refactoring #161
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
else: | ||
map_coordinates = Mock() | ||
|
||
from typing import Dict, List | ||
from typing import Dict, List, Tuple, Union | ||
|
||
__all__ = [ | ||
"distortion_correction_proj_discorpy", | ||
|
@@ -48,7 +48,8 @@ | |
def distortion_correction_proj_discorpy( | ||
data: cp.ndarray, | ||
metadata_path: str, | ||
preview: Dict[str, List[int]], | ||
shift: List[Union[int, int]] = [0, 0], | ||
step: List[Union[int, int]] = [1, 1], | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go with a list, I think the correct type would be If we go with a tuple, the type should be |
||
order: int = 1, | ||
mode: str = "reflect", | ||
): | ||
|
@@ -63,11 +64,11 @@ def distortion_correction_proj_discorpy( | |
The path to the file containing the distortion coefficients for the | ||
data. | ||
|
||
preview : Dict[str, List[int]] | ||
A dict containing three key-value pairs: | ||
- a list containing the `start` value of each dimension | ||
- a list containing the `stop` value of each dimension | ||
- a list containing the `step` value of each dimension | ||
shift: List, optional | ||
Centers of distortion in x (from the left of the image) and y directions (from the top of the image). | ||
|
||
step: List, optional | ||
Steps in x and y directions respectively. They need to be not larger than one. | ||
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the other comment, a note about types. If we go with a list, the type should be If we go with a tuple, the type should be |
||
|
||
order : int, optional. | ||
The order of the spline interpolation. | ||
|
@@ -90,26 +91,25 @@ def distortion_correction_proj_discorpy( | |
|
||
# Use preview information to offset the x and y coords of the center of | ||
# distortion | ||
shift = preview["starts"] | ||
step = preview["steps"] | ||
x_dim = 1 | ||
y_dim = 0 | ||
step_check = max([step[i] for i in [x_dim, y_dim]]) > 1 | ||
if step_check: | ||
det_x_step = step[0] | ||
det_y_step = step[1] | ||
|
||
if det_y_step > 1 or det_x_step > 1: | ||
yousefmoazzam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
msg = ( | ||
"\n***********************************************\n" | ||
"!!! ERROR !!! -> Method doesn't work with the step in" | ||
" the preview larger than 1 \n" | ||
"!!! ERROR !!! -> Method doesn't work with the step parameter" | ||
" larger than 1 \n" | ||
"***********************************************\n" | ||
) | ||
raise ValueError(msg) | ||
|
||
x_offset = shift[x_dim] | ||
y_offset = shift[y_dim] | ||
xcenter = xcenter - x_offset | ||
ycenter = ycenter - y_offset | ||
det_x_shift = shift[0] | ||
det_y_shift = shift[1] | ||
|
||
xcenter = xcenter - det_x_shift | ||
ycenter = ycenter - det_y_shift | ||
|
||
height, width = data.shape[y_dim + 1], data.shape[x_dim + 1] | ||
height, width = data.shape[1], data.shape[2] | ||
xu_list = cp.arange(width) - xcenter | ||
yu_list = cp.arange(height) - ycenter | ||
xu_mat, yu_mat = cp.meshgrid(xu_list, yu_list) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things to note:
Union
isn't needed, regardless of if we choose a list or tuple for theshift
andstep
paramsTuple
import if we go with a list