ohsu-qin/med2image

Name: med2image

Owner: OHSU QIN

Description: Converts medical images to more displayable formats, e.g. NIfTI to jpg.

Forked from: FNNDSC/med2image

Created: 2015-10-02 18:17:51.0

Updated: 2015-10-02 18:17:52.0

Pushed: 2015-10-07 01:42:29.0

Homepage:

Size: 899

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

med2image

Quick Overview
Overview

med2image is a simple Python utility that converts medical image formatted files to more visual friendly ones, such as png and jpg.

Currently, NIfTI and DICOM input formats are understood, while any graphical output type that is supported by matplotlib can be generated.

Dependencies

Make sure that the following dependencies are installed on the host system:

FNNDSC script checkout

An alternate method of installing this script and some of its internal dependencies (error.py, dgmsocket.py, message.py) is to checkout the FNNDSC github scripts repository, https://github.com/FNNDSC/scripts.

Command line arguments
    inputLocation <path>
    Input image file or directory. Typically a DICOM file or a
    nifti volume. When used with the --sliceToConvert option,
    the location is a directory containing DICOM files.

    [-d|--outputDir <outputDir>]
    The directory to contain the converted output image files.

    -o|--outputFileStem <outputFileStem>
    The output file stem to store conversion. If this is specified
    with an extension, this extension will be used to specify the
    output file type.

    SPECIAL CASES:
    For DICOM data, the <outputFileStem> can be set to the value of
    an internal DICOM tag. The tag is specified by preceding the tag
    name with a percent character '%', so

        -o %ProtocolName

    will use the DICOM 'ProtocolName' to name the output file. Note
    that special characters (like spaces) in the DICOM value are
    replaced by underscores '_'.

    Multiple tags can be specified, for example

        -o %PatientName%PatientID%ProtocolName

    and the output filename will have each DICOM tag string as
    specified in order, connected with dashes.

    A special %inputLocation is available to specify the input file that
    was read (without extension).

    [-t|--outputFileType <outputFileType>]
    The output file type. If different to <outputFileStem> extension,
    will override extension in favour of <outputFileType>.

    [-s|--sliceToConvert <sliceToConvert>]
    In the case of volume files, the slice (z) index to convert. Ignored
    for 2D input data. If 'm' is specified, then only convert the middle
    slice in an input volume. The default is to convert all slices.

    [-f|--frameToConvert <sliceToConvert>]
    In the case of 4D volume files, the volume (V) containing the
    slice (z) index to convert. Ignored for 2D or 3D input data. If 'm'
    is specified, then only convert the middle frame in the 4D input
    stack. The default is to convert all slices.

    [--reslice]
    For 3D data only. Assuming [i,j,k] coordinates, the default is to save
    along the 'k' direction. By passing a --reslice image data in the 'i'
    and 'j' directions are also saved. Furthermore, the <outputDir> is
    subdivided into 'slice' (k), 'row' (i), and 'col' (j) subdirectories.
NIfTI conversion

Both 3D and 4D NIfTI input data are understood. In the case of 4D NIfTI, a specific frame can be specified in conjunction with a specific slice index. In most cases, only a slice is required since most NIfTI data is 3D. Furthermore, all slices can be converted, or just the middle one.

Examples
All slices in a volume

To convert all slices in an input NIfTI volume called vol.nii, to save the results in a directory called out and to use as output the file stem name image, do

quivalently and more verbosely,

med2image.py --inputLocation vol.nii     --outputDir out      \
             --outputFileStem image  --outputFileType jpg

 will create the following files in <tt>out</tt>

image-slice000.jpg image-slice001.jpg image-slice002.jpg image-slice003.jpg image-slice004.jpg image-slice005.jpg image-slice006.jpg image-slice007.jpg … image-slice049.jpg image-slice050.jpg image-slice051.jpg image-slice052.jpg image-slice053.jpg

Convert only a single slice
ly, you'll probably only want to convert the "middle" slice in a volume
 example to generate a representative thumbnail of the volume). To do this,
ly specify a <tt>m</tt> to <tt>--sliceToConvert</tt>

or, again, slightly more verbosely and with an outputDirectory specifier

rnatively a specific slice index can be converted. Use

to convert only the 20th slice of the volume.

DICOM conversion
Convert a single DICOM file

To convert a single DICOM file called slice.dcm to slice.jpg, do:

h will create a single file, <tt>slice.jpg</tt> in the current directory.

Convert all DICOMS in a directory/series
onvert all the DICOMS in a directory, simply specifiy a '-1' to the sliceIndex:

Note that this assumes all the DICOM files in the directory inputDir belong to the same series.

Multiple Direction Reslicing

By default, only the slice (or slices) in the acquisition direction are converted. However, by passing a -r to the script, all dimensions are converted. Since the script does not know the anatomical orientation of the image, the directions are simply labeled x, y, and z.

The z direction is the original acquistion (slice) direction, while x and y correspond to planes normal to the row and column directions.

Converted images are stored in subdirectories labeled x, y, and z.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.