Skip to content
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

Harmonise napari plugin and CLI entry points #193

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions brainreg/napari/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def brainreg_register():
freeform_n_steps=6,
freeform_use_n_steps=4,
bending_energy_weight=0.95,
grid_spacing=10,
smoothing_sigma_reference=1,
smoothing_sigma_floating=1,
grid_spacing=-10,
smoothing_sigma_reference=-1.0,
smoothing_sigma_floating=-1.0,
histogram_n_bins_floating=128,
histogram_n_bins_reference=128,
debug=False,
Expand Down Expand Up @@ -239,10 +239,10 @@ def widget(
freeform_use_n_steps: int,
bending_energy_weight: float,
grid_spacing: int,
smoothing_sigma_reference: int,
smoothing_sigma_reference: float,
smoothing_sigma_floating: float,
histogram_n_bins_floating: float,
histogram_n_bins_reference: float,
histogram_n_bins_floating: int,
histogram_n_bins_reference: int,
debug: bool,
reset_button,
check_orientation_button,
Expand Down Expand Up @@ -314,7 +314,9 @@ def widget(
grid_spacing: int
Sets the control point grid spacing in x, y & z.
Smaller grid spacing allows for more local deformations
but increases the risk of over-fitting.
but increases the risk of over-fitting. Positive
values are interpreted as real values in mm, negative values
are interpreted as distance in voxels.
smoothing_sigma_reference: int
Adds a Gaussian smoothing to the reference image (the one being
registered), with the sigma defined by the number. Positive
Expand All @@ -325,11 +327,11 @@ def widget(
registered), with the sigma defined by the number. Positive
values are interpreted as real values in mm, negative values
are interpreted as distance in voxels.
histogram_n_bins_floating: float
histogram_n_bins_floating: int
Number of bins used for the generation of the histograms used
for the calculation of Normalized Mutual Information on the
floating image
histogram_n_bins_reference: float
histogram_n_bins_reference: int
Number of bins used for the generation of the histograms used
for the calculation of Normalized Mutual Information on the
reference image
Expand Down Expand Up @@ -404,9 +406,9 @@ def run():
freeform_n_steps,
freeform_use_n_steps,
bending_energy_weight,
-grid_spacing,
-smoothing_sigma_reference,
-smoothing_sigma_floating,
grid_spacing,
smoothing_sigma_reference,
smoothing_sigma_floating,
histogram_n_bins_floating,
histogram_n_bins_reference,
debug=False,
Expand Down Expand Up @@ -463,6 +465,7 @@ def run():
n_free_cpus,
save_original_orientation=save_original_orientation,
brain_geometry=brain_geometry.value,
debug=debug,
)

logging.info("Calculating volumes of each brain area")
Expand Down
36 changes: 29 additions & 7 deletions brainreg/napari/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,52 @@
)


def downsample_and_save_brain(img_layer, scaling):
def downsample_and_save_brain(
img_layer,
scaling,
anti_aliasing=True,
preserve_range=True,
mode="constant",
):
first_frame_shape = skimage.transform.rescale(
img_layer.data[0], scaling[1:2], anti_aliasing=True
img_layer.data[0],
scaling[1:2],
anti_aliasing=anti_aliasing,
preserve_range=preserve_range,
mode=mode,
).shape
preallocated_array = np.empty(
(img_layer.data.shape[0], first_frame_shape[0], first_frame_shape[1])
)
print("downsampling data in x, y")
print("Downsampling data in x, y")

Check warning on line 60 in brainreg/napari/util.py

View check run for this annotation

Codecov / codecov/patch

brainreg/napari/util.py#L60

Added line #L60 was not covered by tests
for i, img in tqdm(enumerate(img_layer.data)):
down_xy = skimage.transform.rescale(
img, scaling[1:2], anti_aliasing=True
img,
scaling[1:2],
anti_aliasing=anti_aliasing,
preserve_range=preserve_range,
mode=mode,
)
preallocated_array[i] = down_xy

first_ds_frame_shape = skimage.transform.rescale(
preallocated_array[:, :, 0], [scaling[0], 1], anti_aliasing=True
preallocated_array[:, :, 0],
[scaling[0], 1],
anti_aliasing=anti_aliasing,
preserve_range=preserve_range,
mode=mode,
).shape
downsampled_array = np.empty(
(first_ds_frame_shape[0], first_frame_shape[0], first_frame_shape[1])
)
print("downsampling data in z")
print("Downsampling data in z")

Check warning on line 81 in brainreg/napari/util.py

View check run for this annotation

Codecov / codecov/patch

brainreg/napari/util.py#L81

Added line #L81 was not covered by tests
for i, img in tqdm(enumerate(preallocated_array.T)):
down_xyz = skimage.transform.rescale(
img, [1, scaling[0]], anti_aliasing=True
img,
[1, scaling[0]],
anti_aliasing=anti_aliasing,
preserve_range=preserve_range,
mode=mode,
)
downsampled_array[:, :, i] = down_xyz.T
return downsampled_array
Expand Down
Loading