-
-
Save everyoneelse/eefa502afb13ced81ed48883c1528ed5 to your computer and use it in GitHub Desktop.
Revisions
-
fepegar revised this gist
Nov 12, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,9 @@ * SimpleITK * NumPy # Install * [`conda`](https://conda.io/miniconda.html) * [SimpleITK](http://www.simpleitk.org/) and [NumPy](http://www.numpy.org/): ``` conda install numpy -y conda install -c simpleitk simpleitk -y -
fepegar revised this gist
Nov 12, 2017 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # Requirements: * Python * SimpleITK * NumPy * Install [`conda`](https://conda.io/miniconda.html) * Install SimpleITK and numpy ``` conda install numpy -y conda install -c simpleitk simpleitk -y ``` -
fepegar created this gist
Nov 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ Created on Fri Nov 10 16:51:47 2017 @author: fernando """ import os import numpy as np import SimpleITK as sitk def make_mips(image_path, output_dir): image = sitk.ReadImage(image_path) image_size = image.GetSize() basename = os.path.basename(image_path) if not os.path.isdir(output_dir): os.makedirs(output_dir) for dim in range(3): projection = sitk.MaximumProjection(image, dim) if image_size[dim] % 2: # odd number voxel = [0, 0, 0] voxel[dim] = (image_size[dim] - 1) / 2 origin = image.TransformIndexToPhysicalPoint(voxel) else: # even voxel1 = np.array([0, 0, 0], int) voxel2 = np.array([0, 0, 0], int) voxel1[dim] = image_size[dim] / 2 - 1 voxel2[dim] = image_size[dim] / 2 point1 = np.array(image.TransformIndexToPhysicalPoint(voxel1.tolist())) point2 = np.array(image.TransformIndexToPhysicalPoint(voxel2.tolist())) origin = np.mean(np.vstack((point1, point2)), 0) projection.SetOrigin(origin) projection.SetDirection(image.GetDirection()) proj_basename = basename.replace('.nii.gz', '_mip_{}.nii.gz'.format(dim)) sitk.WriteImage(projection, os.path.join(output_dir, proj_basename))