Skip to content

Commit

Permalink
Merge pull request #1 from MotionCorrect/hanna
Browse files Browse the repository at this point in the history
add lib versioning
  • Loading branch information
cakester authored Mar 25, 2021
2 parents b977a20 + 2ae8d9c commit 5e402fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 16 additions & 4 deletions ivadomed/scripts/prepare_dataset_vertebral_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def mask2label(path_label, aim=0):
return list_label_image


def create_fake_nib_image():
timepoints = 200
nvox = 20

# Creates fake data to test with
test_data = np.random.random((nvox, nvox, nvox, timepoints))
time = np.linspace(0, 400, timepoints)
freq = 1
test_data = test_data + np.sin(2 * np.pi * freq * time)
xform = np.eye(4) * 2
test_img = nib.nifti1.Nifti1Image(test_data, xform)
return test_img


def extract_mid_slice_and_convert_coordinates_to_heatmaps(path, suffix, aim=-1):
"""
This function takes as input a path to a dataset and generates a set of images:
Expand Down Expand Up @@ -69,15 +83,13 @@ def extract_mid_slice_and_convert_coordinates_to_heatmaps(path, suffix, aim=-1):
sub = t[i]
path_image = os.path.join(path, t[i], 'anat', t[i] + suffix + '.nii.gz')
if os.path.isfile(path_image):
path_label = os.path.join(path, 'derivatives', 'labels', t[i], 'anat', t[i] + suffix +
'_labels-disc-manual.nii.gz')
list_points = mask2label(path_label, aim=aim)
list_points = [[0, 0, 0, 0]]
image_ref = nib.load(path_image)
nib_ref_can = nib.as_closest_canonical(image_ref)
imsh = np.array(nib_ref_can.dataobj).shape
mid_nifti = imed_preprocessing.get_midslice_average(path_image, list_points[0][0], slice_axis=0)
nib.save(mid_nifti, os.path.join(path, t[i], 'anat', t[i] + suffix + '_mid.nii.gz'))
lab = nib.load(path_label)
lab = create_fake_nib_image()
nib_ref_can = nib.as_closest_canonical(lab)
label_array = np.zeros(imsh[1:])

Expand Down
8 changes: 1 addition & 7 deletions testing/functional_tests/test_visualize_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ def test_visualize_transforms_n_1():
__input_file__ = os.path.join(__data_testing_dir__, 'sub-unf01/anat/sub-unf01_T1w.nii.gz')
__output_dir__ = os.path.join(__tmp_dir__, "output_visualize_transforms_n_1")
__config_file__ = os.path.join(__data_testing_dir__, "model_config.json")
__label_file__ = os.path.join(__data_testing_dir__,
'derivatives/labels/sub-test001/anat/sub-unf01_T1w_seg-manual.nii.gz')
visualize_transforms.main(args=['--input', __input_file__,
'--output', __output_dir__,
'--config', __config_file__,
'-r', __label_file__])
'--config', __config_file__])
assert os.path.exists(__output_dir__)
output_files = os.listdir(__output_dir__)
assert len(output_files) == 5
Expand All @@ -33,12 +30,9 @@ def test_visualize_transforms_n_2():
__input_file__ = os.path.join(__data_testing_dir__, 'sub-unf01/anat/sub-unf01_T1w.nii.gz')
__output_dir__ = os.path.join(__tmp_dir__, "output_visualize_transforms_n_2")
__config_file__ = os.path.join(__data_testing_dir__, "model_config.json")
__label_file__ = os.path.join(__data_testing_dir__,
'derivatives/labels/sub-test001/anat/sub-unf01_T1w_seg-manual.nii.gz')
visualize_transforms.main(args=['--input', __input_file__,
'--output', __output_dir__,
'--config', __config_file__,
'-r', __label_file__,
'-n', '2'])
assert os.path.exists(__output_dir__)
output_files = os.listdir(__output_dir__)
Expand Down

0 comments on commit 5e402fe

Please sign in to comment.