Skip to content

Instantly share code, notes, and snippets.

@everyoneelse
Forked from fepegar/README.md
Created January 30, 2024 05:31
Show Gist options
  • Save everyoneelse/eefa502afb13ced81ed48883c1528ed5 to your computer and use it in GitHub Desktop.
Save everyoneelse/eefa502afb13ced81ed48883c1528ed5 to your computer and use it in GitHub Desktop.

Revisions

  1. @fepegar fepegar revised this gist Nov 12, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,9 @@
    * SimpleITK
    * NumPy

    * Install [`conda`](https://conda.io/miniconda.html)
    * Install SimpleITK and 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
  2. @fepegar fepegar revised this gist Nov 12, 2017. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions README.md
    Original 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
    ```
  3. @fepegar fepegar created this gist Nov 12, 2017.
    40 changes: 40 additions & 0 deletions mip.py
    Original 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))