(Python)将mgz卷过滤到jpg/png图像切片的pervoxelvalue目录的实用程序

mgz2imgslices的Python项目详细描述


快速概述

  • 按体素值将mgz卷文件过滤到组织良好的图像文件目录中。在

概述

mgz2imgslices是一个简单的Python实用程序,它从mgz卷文件中筛选“标签”,并将每个标签集保存为(默认情况下)png文件的片段,组织成一系列目录,每个标签集一个。在

一个mgz格式文件只包含图像值的3D卷数据结构。通常这些值被解释为图像强度。但是,有时它们可以解释为标签标识符。不管解释如何,体积图像数据只是体积的每个体素中的一个数值。在

此脚本将扫描输入mgz卷,并为每个体素值创建一个新的输出目录。在该目录中,将有一组numpy数组(.npy文件),每片原始卷一个。这些numpy数组只包含原始数据集中的体素值,这些值都具有特定的体素值。在

以这种方式,mgz2imgslices也可以看作是mgz卷文件的动态过滤器,该卷文件将每个体素值过滤到其自己的输出目录.npy文件中。在

依赖关系

请确保在主机系统上安装了以下依赖项(或者更好,是python3virtual env):

  • pfmisc:(用于颜色支持等的通用杂项模块)
  • nibabel:(读取NIfTI文件)
  • numpy:(支持大型多维数组和矩阵)
  • imageio:(读写图像数据的接口)
  • pandas:(数据操作和分析)
  • re:(支持正则表达式)
  • time:(支持各种与时间相关的函数)

假设

本文档假定使用UNIX约定和bashshell。这个脚本在Windows下应该可以正常工作,但是我们还没有在这个平台上进行测试——我们的开发环境是Linux Ubuntu和macOS。在

安装

Python模块

安装此脚本及其所有依赖项的一种方法是从PyPI获取它。在

pip3 install mgz2imgslices

Docker容器

我们还提供了一个docker容器mgz2imgslices,作为一个符合ChRIS规范的平台插件https://github.com/FNNDSC/pl-mgz2imgslices-请参考该页面以获取有关运行dockerized容器的信息。容器化版本公开了与此模块类似的CLI和功能。在

如何使用

mgz2imgslices至少需要以下命令行参数:

  • -i | --inputFile <inputFile>:要转换的输入.mgz文件。在
  • -d | --outputDir <outputDir>:输出目录。这又将包含几个子目录,在输入mgz文件中每个图像体素值一个。每个子目录都将包含npy文件,并过滤为该体素值。在
  • -o | --outputFileStem <outputFileStem>:标签目录中输出文件的名称(numpy数组和png/jpg图像)

注意:

  • 此Python实用程序的--lookupTablearg要求传递FreeSurferColorLUT.txt(或其他相同格式的LUT文件),该文件应该存在于inputDir中。在
  • 如果您正在使用docker映像(请访问https://github.com/FNNDSC/pl-mgz2imgslices)来运行此实用程序,则可以对__fs__或{tt31}$参数使用__fs____val__。在

示例

首先,让我们创建一个目录,比如devel,只要你喜欢它。我们将在这个目录中放置一些测试数据来处理这个插件。在

^{pr2}$

现在,我们需要获取样本MGZ数据。在

mgzdata

git clone https://github.com/FNNDSC/mgz_converter_dataset.git

确保mgz_converter_dataset目录放在devel目录中。在

  • 确保您当前的工作目录是devel。此时它应该包含mgz_converter_dataset。在
  • devel中创建一个名为results的输出目录。在
mkdir results && chmod 777 results
例1
  • 使用以下命令运行mgz2imgslices。根据需要改变论点。在
mgz2imgslices
    -I ${DEVEL}/mgz_converter_dataset/100307/                              \
    --inputFile aparc.a2009s+aseg.mgz                                       \
    --outputDir ${DEVEL}/results/                                          \
    --outputFileStem sample                                                \
    --outputFileType png                                                   \
    --saveImages
    --label label                                                          \
    --wholeVolume FullVolume                                               \
    --lookupTable FreeSurferColorLUT.txt                                                  \
    --skipLabelValueList 0,4,7

skipLabelValueList将跳过输入mgz中数值为0, 4, 7的任何体素。请注意,每个输出筛选目录都将有一个名称前缀字符串label,并且应该出现类似于以下内容的内容:

results/label-Left-Cerebral-White-Matter/sample-000.png
                    ...
results/label-Left-Cerebral-White-Matter/sample-00255.png

...
...

results/label-ctx_rh_S_temporal_transverse/sample-000.png
                    ...
results/label-ctx_rh_S_temporal_transverse/sample-00255.png

命令行参数

ARGS

    [-i|--inputFile  <inputFile>]
    Input file to convert. Should be an ``mgz`` file.

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

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

    Should be a ``png``only.

    [--saveImages]
    If specified as True(boolean), will save the slices of the mgz file as
    ".png" image files along with the numpy files.

    [--label <prefixForLabelDirectories>]
    Prefixes the string <prefixForLabelDirectories> to each filtered
    directory name. This is mostly for possible downstream processing,
    allowing a subsequent operation to easily determine which of the output
    directories correspond to labels.

    [-n|--normalize]
    If specified as True(boolean), will normalize the output image pixel values to
    0 and 1, otherwise pixel image values will retain the value in
    the original input volume.

    [-l|--lookupTable <LUTfile>]
    Need to pass a <LUTfile> (eg. FreeSurferColorLUT.txt)
    to perform a looktup on the filtered voxel label values
    according to the contents of the <LUTfile>. This <LUTfile> should
    conform to the FreeSurfer lookup table format (documented elsewhere).

    Note that the special <LUTfile> string ``__val__``, ``__fs__`` or ``__none__``
    can be passed only when running the docker image (fnndsc/pl-mgz2imageslices)
    of this utility which effectively means "no <LUTfile>".
    In this case, the numerical voxel values are used for output directory names.
    This special string is really only useful for scripted cases of running
    this application when modifying the CLI is more complex than simply setting
    the <LUTfile> to ``__val__``.

    While running the docker image, you can also pass ``__fs__`` which will use
    the FreeSurferColorLUT.txt from within the docker container to perform a
    looktup on the filtered voxel label values according to the contents of
    the FreeSurferColorLUT.txt

    [--skipAllLabels]
    Skips all labels and converts only the whole mgz volume to png/jpg images.

    [-s|--skipLabelValueList <ListOfLabelNumbersToSkip>]
    If specified as a comma separated string of label numbers,
    will not create directories of those label numbers.

    [-f|--filterLabelValues <ListOfVoxelValuesToInclude>]
    The logical inverse of the [skipLabelValueList] flag. If specified,
    only filter the comma separated list of passed voxel values from the
    input volume.

    The detault value of "-1" implies all voxel values should be filtered.

    [-w|--wholeVolume <wholeVolDirName>]
    If specified, creates a diretory called <wholeVolDirName> (within the
    outputdir) containing PNG/JPG images files of the entire input.

    This effectively really creates a PNG/JPG conversion of the input
    mgz file.

    Values in the image files will be the same as the original voxel
    values in the ``mgz``, unless the [--normalize] flag is specified
    in which case this creates a single-value mask of the input image.

    [-h|--help]
    If specified, show help message and exit.

    [--json]
    If specified, show json representation of app and exit.

    [--man]
    If specified, print (this) man page and exit.

    [--meta]
    If specified, print plugin meta np_data and exit.

    [--savejson <DIR>]
    If specified, save json representation file to DIR and exit.

    [-v <level>|--verbosity <level>]
    Verbosity level for app. Not used currently.

    [--version]
    If specified, print version number and exit.

    [-y|--synopsis]
    Show short synopsis.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
继承如何将这个Java接口和继承结构转换为Golang?   java set callout image mapbox 安卓   java无法访问Android Studio中的XML表单主活动   java将结果集中的varchar放入ArrayList   java应用程序引发所有访问的facebook OAuth异常   java如何使用TestNG在两个不同的浏览器中并行运行两个测试方法?   java操作栏上下文菜单   java Javafx将标签绑定到StringProperty的位置   java如何正确初始化JNA中“Structure”中的数组字段?   如何通过读取Java中的URL来知道图像是否存在?   java如何在Android 4.0中从HttpClient获取响应   scala是一款带有嵌入式java的独立播放应用程序   为什么我的动画第一次播放时不流畅?   java我在寻找什么样的构造函数和访问修饰符组合?   java在给出这个时间表的情况下,我如何判断时间复杂度?