Browse Source

gin commit from rMBP-15-Malthe.local

New files: 1
Modified files: 12
malthe.nielsen 4 years ago
parent
commit
f92028e933

BIN
Example/.DS_Store


+ 1 - 1
Example/Brain_example.tif

@@ -1 +1 @@
-/annex/objects/MD5-s218048235--f54b593481abb5cc2ae30af344baf2be
+/annex/objects/MD5-s218051448--31ee94f6cf1493311aea04b64b65faf4

+ 1 - 1
Example/preprocess.py

@@ -91,7 +91,7 @@ def split_nii_channels(nii_path, out_dir=None, flip=False, mask_index=-1, bias=F
         if i == mask_index and bias:
             bias_field_correction(str(out_path), str(out_path))
             corrected = nib.load(str(out_path))
-            corrected_data = corrected.get_data()
+            corrected_data = corrected.get_fdata()
             corrected_normalized = corrected_data / np.mean(corrected_data[corrected_data != 0])
             nii_corrected = nib.Nifti1Image(corrected_normalized, corrected.affine, corrected.header)
             nib.save(nii_corrected, str(out_path))

+ 3 - 3
Example/registration.py

@@ -12,9 +12,9 @@ def full_registration(fixed, moving, output='full_trans.nii', transform_pre=''):
         metric=['CC', 'MI'] * 3,
         convergence_threshold=[1.e-7],
         number_of_iterations=[[1000, 1000, 1000, 1000], [1000, 1000, 1000, 1000],
-                              [1000, 1000, 1000, 1000, 1000]],
-        smoothing_sigmas=[[4, 4, 2, 2], [4, 4, 2, 2], [4, 2, 2, 2, 1]],
-        shrink_factors=[[32, 16, 8, 4], [32, 16, 8, 4], [16, 8, 4, 2, 1]],
+                              [1000, 1000, 1000, 1000]],
+        smoothing_sigmas=[[4, 4, 2, 2], [4, 4, 2, 2], [4, 2, 2, 1]],
+        shrink_factors=[[32, 16, 8, 4], [32, 16, 8, 4], [16, 8, 4, 2]],
         initial_moving_transform_com=1,
         interpolation='BSpline',
         metric_weight=[0.5] * 6,

+ 2 - 2
Example/runner.py

@@ -28,8 +28,8 @@ def find_optimal_index(slice_path, template_path, approx, temporary_directory, d
         tools.save_slice(str(template_path), template_slice_loc, i, np.eye(4), _slice.header)
         registration.rigid_registration(template_slice_loc, str(slice_path), registered_loc, transform_prefix)
 
-        template_data = nib.load(str(template_slice_loc)).get_data()
-        registered_data = nib.load(registered_loc).get_data()
+        template_data = nib.load(str(template_slice_loc)).get_fdata()
+        registered_data = nib.load(registered_loc).get_fdata()
         registered_data = tools.resize_im(registered_data, template_data)
         nib.save(nib.Nifti1Image(registered_data, np.eye(4)), registered_loc)
 

+ 1 - 1
Example/runner_example.sh

@@ -1,3 +1,3 @@
 #!/bin/bash
-python3.7 ./runner.py ./Brain_example.tif ./data/dapi_template_segmentation_full.nii.gz ./data/dapi_template.nii.gz -1.66 ./ --dapi 2
+python3.7 ./runner.py ./Brain_example.tif ./data/dapi_template_segmentation_full.nii.gz ./data/dapi_template.nii.gz 1.83 ./ --dapi 2
 

+ 1 - 1
Example/tools.py

@@ -8,7 +8,7 @@ import shutil
 from preprocess import mask_foreground
 def save_slice(template, filename, index, affine=np.eye(4), header=None):
     _slice = nib.load(str(template))
-    _slice_data = _slice.get_data()
+    _slice_data = _slice.get_fdata()
 
     newimg = nib.Nifti1Image(_slice_data[:, index, :], affine, header)
     newimg.header['pixdim'] = header['pixdim']

+ 11 - 1
README.md

@@ -69,7 +69,17 @@ Program for automatic segmentation to a DAPI-stained coronal mouse brain slices.
 * Use runner.py to preprocess and output a sgementation registred to the slice
   in a designated output folder
 * Use preprocess.py to prepare input slice for automatic registration  
-  
+ 
+## Example.zip
+In the repository is included a zip file that contains all the files and scripts
+used in order to run an Example of the program. To run the example, download and
+unzip the folder and open the folder in a terminal window. Make sure that the
+enviroment is setup correct as descirbed above, and then run the shell fill by 
+```sh
+bash runner_example.sh
+```
+
+
 ## Details
 Detailed parameter description.
 

+ 1 - 1
automatic_segmentation_program/preprocess.py

@@ -91,7 +91,7 @@ def split_nii_channels(nii_path, out_dir=None, flip=False, mask_index=-1, bias=F
         if i == mask_index and bias:
             bias_field_correction(str(out_path), str(out_path))
             corrected = nib.load(str(out_path))
-            corrected_data = corrected.get_data()
+            corrected_data = corrected.get_fdata()
             corrected_normalized = corrected_data / np.mean(corrected_data[corrected_data != 0])
             nii_corrected = nib.Nifti1Image(corrected_normalized, corrected.affine, corrected.header)
             nib.save(nii_corrected, str(out_path))

+ 3 - 3
automatic_segmentation_program/registration.py

@@ -12,9 +12,9 @@ def full_registration(fixed, moving, output='full_trans.nii', transform_pre=''):
         metric=['CC', 'MI'] * 3,
         convergence_threshold=[1.e-7],
         number_of_iterations=[[1000, 1000, 1000, 1000], [1000, 1000, 1000, 1000],
-                              [1000, 1000, 1000, 1000, 1000]],
-        smoothing_sigmas=[[4, 4, 2, 2], [4, 4, 2, 2], [4, 2, 2, 2, 1]],
-        shrink_factors=[[32, 16, 8, 4], [32, 16, 8, 4], [16, 8, 4, 2, 1]],
+                              [1000, 1000, 1000, 1000]],
+        smoothing_sigmas=[[4, 4, 2, 2], [4, 4, 2, 2], [4, 2, 2, 1]],
+        shrink_factors=[[32, 16, 8, 4], [32, 16, 8, 4], [16, 8, 4, 2]],
         initial_moving_transform_com=1,
         interpolation='BSpline',
         metric_weight=[0.5] * 6,

+ 2 - 2
automatic_segmentation_program/runner.py

@@ -28,8 +28,8 @@ def find_optimal_index(slice_path, template_path, approx, temporary_directory, d
         tools.save_slice(str(template_path), template_slice_loc, i, np.eye(4), _slice.header)
         registration.rigid_registration(template_slice_loc, str(slice_path), registered_loc, transform_prefix)
 
-        template_data = nib.load(str(template_slice_loc)).get_data()
-        registered_data = nib.load(registered_loc).get_data()
+        template_data = nib.load(str(template_slice_loc)).get_fdata()
+        registered_data = nib.load(registered_loc).get_fdata()
         registered_data = tools.resize_im(registered_data, template_data)
         nib.save(nib.Nifti1Image(registered_data, np.eye(4)), registered_loc)
 

+ 1 - 1
automatic_segmentation_program/tools.py

@@ -8,7 +8,7 @@ import shutil
 from preprocess import mask_foreground
 def save_slice(template, filename, index, affine=np.eye(4), header=None):
     _slice = nib.load(str(template))
-    _slice_data = _slice.get_data()
+    _slice_data = _slice.get_fdata()
 
     newimg = nib.Nifti1Image(_slice_data[:, index, :], affine, header)
     newimg.header['pixdim'] = header['pixdim']