Package: mgz2imagetree
Quick OverviewRecursively walk down a directory tree and extractMGZlabels,
creating image slices for each individual label preserving directory structure in output tree.Overviewmgz2imagetreeis a simple Python utility that recursively walks down aninputdir, extracts all themgzfiles, filters “labels” frommgzvolume files and saves each label set as slices of (by default)pngfiles (using the Python utility calledmgz2imgslices), organized into a series of directories, one per label set for each subject, and replicates the entire direcotry structure in theoutputdir.This utility also allows to pass all the CLI arguments that are specific tomgz2imgslices.
NOTE:Anmgzformat 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.DependenciesMake sure that the following dependencies are installed on your host system (or even better, apython3virtual 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.AssumptionsThis document assumes UNIX conventions and abashshell. The script should work fine under Windows, but we have not actively tested on that platform – our dev envs are Linux Ubuntu and macOS.InstallationPython moduleOne method of installing this script and all of its dependencies is by fetching it fromPyPI.pip3installmgz2imagetreeHow to Usemgz2imagetreeneeds 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 shouldnothave a file extension, or rather, any “.” in the name are considered part of the stem and arenotconsidered extensions.[--feature<MGZFileToConvertToLabelledSegments>]: The feature file containing the cortical strip which needs to be filtered into it constituent cortical segments usingmgz2imgslices[--imageFile<MGZFileImageFile>]: The raw 3D mgz image file that needs to be split and stored as slices in the corresponding subject’s output directory.ExamplesFirst, let’s create a directory, saydevelwherever you feel like it. We will place some test data in this directory to process with this plugin.cd~/mkdirdevelcddevelexportDEVEL=$(pwd)Now, we need to fetch sample MGZ data.PullmgzdataWe provide a sample directory of a few.mgzvolumes here. (https://github.com/FNNDSC/mgz_converter_dataset.git)Clone this repository (mgz_converter_dataset) to your local computer.gitclonehttps://github.com/FNNDSC/mgz_converter_dataset.gitMake sure themgz_converter_datasetdirectory is placed in the devel directory.Make sure your current working directory isdevel. At this juncture it should containmgz_converter_dataset.Create an output directory namedresultsindevel.mkdirresults&&chmod777resultsEXAMPLE 1Runmgz2imgslicesusing the following command. Change the arguments according to your need.mgz2imagetree--inputDir${DEVEL}/mgz_converter_dataset/\--outputDir${DEVEL}/results/\--featureaparc.a2009s+aseg.mgz\--imageFilebrain.mgz\--outputFileStemsample\--outputFileTypejpg\--labellabel\--wholeVolumeFullVolume\--rawDirNameRawImageDirectory\