Skip to content

Commit

Permalink
Merge branch 'main' into n-free-cpus
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson authored Apr 30, 2024
2 parents f23fc83 + 8012442 commit 570c569
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
29 changes: 18 additions & 11 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,
n_free_cpus=2,
Expand Down Expand Up @@ -195,15 +195,19 @@ def brainreg_register():
label="bending_energy_weight",
),
grid_spacing=dict(
value=DEFAULT_PARAMETERS["grid_spacing"], label="grid_spacing"
value=DEFAULT_PARAMETERS["grid_spacing"],
label="grid_spacing",
min=-100,
),
smoothing_sigma_reference=dict(
value=DEFAULT_PARAMETERS["smoothing_sigma_reference"],
label="smoothing_sigma_reference",
min=-99.0,
),
smoothing_sigma_floating=dict(
value=DEFAULT_PARAMETERS["smoothing_sigma_floating"],
label="smoothing_sigma_floating",
min=-99.0,
),
histogram_n_bins_floating=dict(
value=DEFAULT_PARAMETERS["histogram_n_bins_floating"],
Expand Down Expand Up @@ -244,7 +248,7 @@ 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,
Expand Down Expand Up @@ -320,7 +324,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 @@ -331,11 +337,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 @@ -412,9 +418,9 @@ def run(n_free_cpus):
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 @@ -474,6 +480,7 @@ def run(n_free_cpus):
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 @@ -41,30 +41,52 @@ def initialise_brainreg(
)


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")
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")
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

0 comments on commit 570c569

Please sign in to comment.