Skip to main content

Quick Overview

Recursively walk down a directory tree and extract MGZ labels, creating image slices for each individual label preserving directory structure in output tree.

Overview

mgz2imagetree is a simple Python utility that recursively walks down an inputdir, extracts all the mgz files, filters “labels” from mgz volume files and saves each label set as slices of (by default) png files (using the Python utility called mgz2imgslices), organized into a series of directories, one per label set for each subject, and replicates the entire direcotry structure in the outputdir.

This utility also allows to pass all the CLI arguments that are specific to mgz2imgslices. NOTE:

An mgz format file simply contains a 3D volume data structure of image values. Often these values are interpreted to be image intensities. Sometimes, however, they can be interpreted as label identifiers. Regardless of the interpretation, the volume image data is simply a number value in each voxel of the volume.

Dependencies

Make sure that the following dependencies are installed on your host system (or even better, a python3 virtual env):

pfmisc : (a general miscellaneous module for color support, etc) nibabel : (to read NIfTI/MGZ files) numpy : (to support large, multidimensional arrays and matrices) imageio : (interface to read and write image data) pftree : Create a dictionary representation of a filesystem hierarchy.

Assumptions

This document assumes UNIX conventions and a bash shell. The script should work fine under Windows, but we have not actively tested on that platform – our dev envs are Linux Ubuntu and macOS.

Installation

Python module

One method of installing this script and all of its dependencies is by fetching it from PyPI.

pip3 install mgz2imagetree

How to Use

mgz2imagetree needs at a minimum the following required command line arguments:

  • [-I|--inputDir <inputDir>] : Input directory to examine. By default, the first file in this directory is examined for its tag information.

  • [-O|--outputDir <outputDir>] : The output root directory that will contain a tree structure identical to the input directory, and each “leaf” node will contain the analysis results.

  • [-o|--outputFileStem <outputFileStem>] : The output file stem to store data. This should not have a file extension, or rather, any “.” in the name are considered part of the stem and are not considered extensions.

  • [--feature <MGZFileToConvertToLabelledSegments>] : The feature file containing the cortical strip which needs to be filtered into it constituent cortical segments using mgz2imgslices

  • [--imageFile <MGZFileImageFile>] : The raw 3D mgz image file that needs to be split and stored as slices in the corresponding subject’s output directory.

Examples

First, let’s create a directory, say devel wherever you feel like it. We will place some test data in this directory to process with this plugin.

cd ~/
mkdir devel
cd devel
export DEVEL=$(pwd)

Now, we need to fetch sample MGZ data.

Pull mgz data

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

Make sure the mgz_converter_dataset directory is placed in the devel directory.

  • Make sure your current working directory is devel. At this juncture it should contain mgz_converter_dataset.

  • Create an output directory named results in devel.

mkdir results && chmod 777 results

EXAMPLE 1

  • Run mgz2imgslices using the following command. Change the arguments according to your need.

mgz2imagetree
    --inputDir ${DEVEL}/mgz_converter_dataset/                             \
    --outputDir ${DEVEL}/results/                                          \
    --feature aparc.a2009s+aseg.mgz                                        \
    --imageFile brain.mgz                                                      \
    --outputFileStem sample                                                \
    --outputFileType jpg                                                   \
    --label label                                                          \
    --wholeVolume FullVolume                                               \
    --rawDirName RawImageDirectory                                         \

Metadata

Release files for mgz2imagetree 1.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mgz2imagetree 1.1.8
File Size Uploaded Provenance
mgz2imagetree-1.1.8.tar.gz 12.6 kB Without provenance Details

Release files / mgz2imagetree-1.1.8.tar.gz

Download URL mgz2imagetree-1.1.8.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0cfa2188f0ee082a3a938c26aac028fa8b5064902e5d9460e0d19d4fec57e55c
BLAKE2b-256 checksum
How to use checksums
2ecbc815333b80f785b18099e092f30f077abc03dd8aa7019465377e4e97cdc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.5

Security for mgz2imagetree 1.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page