From 07078987879b2f7961ec30a58502011e049a6c78 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 19 May 2020 10:40:09 -0400 Subject: [PATCH 01/63] Minor updates --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index d72ba06..f9de0ee 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -med2image -========= +med2image -- 2.1.0 +================== Quick Overview -------------- @@ -21,6 +21,7 @@ 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 files) - ``pydicom`` (to read DICOM files) - ``matplotlib`` (to save data in various image formats) From a812bc6252aa3d94c2aef6c49abc7ee584c887b8 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 19 May 2020 10:40:30 -0400 Subject: [PATCH 02/63] Minor cleanup --- bin/med2image | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/med2image b/bin/med2image index 0711cc2..e8f42ad 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,9 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.0.1" -#import pdb; pdb.set_trace() - +str_version = "2.1.0" str_desc = Colors.CYAN + """ _ _____ _ @@ -270,6 +268,7 @@ parser.add_argument('-v', '--version', # parse passed arguments args = parser.parse_args() +# Do some minor CLI checks if args.b_version: print("Version: %s" % str_version) sys.exit(1) @@ -283,12 +282,12 @@ if args.man or args.synopsis: print(str_help) sys.exit(1) +# Create the object imgConverter = med2image.object_factoryCreate(args).C_convert -if args.func: - imgConverter.func = args.func +# Set possible function handling +if args.func: imgConverter.func = args.func -# pudb.set_trace() # And now run it! imgConverter.tic() imgConverter.run() From 4b3bcfa220f52ae1fb5b82ac29fe821eb439dc33 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 19 May 2020 10:41:30 -0400 Subject: [PATCH 03/63] Remove some dead code --- med2image/med2image.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/med2image/med2image.py b/med2image/med2image.py index 4b1b02b..b396753 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -7,22 +7,16 @@ import numpy as np import re import time -# import pudb +import pudb # System dependency imports -import nibabel as nib -import pydicom as dicom +import nibabel as nib +import pydicom as dicom import pylab -import matplotlib.cm as cm +import matplotlib.cm as cm -# # Project specific imports -# from . import error -# from . import message as msg -# from . import systemMisc as misc import pfmisc - -# pfurl local dependencies from pfmisc._colors import Colors from pfmisc.message import Message From ef42ec15101bff997489aa9b08b9d865d6018f4b Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 19 May 2020 10:41:44 -0400 Subject: [PATCH 04/63] Bump to 2.1.0 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 61c6221..2b41b88 100644 --- a/setup.py +++ b/setup.py @@ -12,14 +12,14 @@ def readme(): setup( name = 'med2image', - version = '2.0.1', + version = '2.1.0', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', author_email = 'dev@babymri.org', url = 'https://github.com/FNNDSC/med2image', packages = ['med2image'], - install_requires = ['nibabel', 'dicom', 'pydicom', 'numpy', 'matplotlib', 'pillow'], + install_requires = ['pfmisc' 'nibabel', 'pydicom', 'numpy', 'matplotlib', 'pillow'], #test_suite = 'nose.collector', #tests_require = ['nose'], scripts = ['bin/med2image'], From 798cc46be947bd60b47327016a63debd172be6a0 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 19 May 2020 11:57:45 -0400 Subject: [PATCH 05/63] Fix typo in setup.py and bump version to 2.1.1 --- README.rst | 2 +- bin/med2image | 2 +- setup.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index f9de0ee..6694dff 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image -- 2.1.0 +med2image -- 2.1.1 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index e8f42ad..5789fc1 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.1.0" +str_version = "2.1.1" str_desc = Colors.CYAN + """ _ _____ _ diff --git a/setup.py b/setup.py index 2b41b88..1a17323 100644 --- a/setup.py +++ b/setup.py @@ -12,14 +12,14 @@ def readme(): setup( name = 'med2image', - version = '2.1.0', + version = '2.1.1', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', author_email = 'dev@babymri.org', url = 'https://github.com/FNNDSC/med2image', packages = ['med2image'], - install_requires = ['pfmisc' 'nibabel', 'pydicom', 'numpy', 'matplotlib', 'pillow'], + install_requires = ['pfmisc', 'nibabel', 'pydicom', 'numpy', 'matplotlib', 'pillow'], #test_suite = 'nose.collector', #tests_require = ['nose'], scripts = ['bin/med2image'], From ab6f8121c5a32c78fe5a1c80791ff1a35148cd92 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Tue, 19 May 2020 16:07:28 -0400 Subject: [PATCH 06/63] Modified README.rst --- README.rst | 107 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 84 insertions(+), 23 deletions(-) diff --git a/README.rst b/README.rst index f9de0ee..0e24fa9 100644 --- a/README.rst +++ b/README.rst @@ -44,6 +44,24 @@ Should you get an error about `python3-tk` not installed, simply do (for example sudo apt-get update sudo apt-get install -y python3-tk +How to Use +---------- + +The med2image needs the following required arguments to run the application: + +- -i|--inputFile + Input file to convert. Typically a DICOM file or a nifti volume. + +- -d|--outputDir + The directory to contain the converted output image files. + +.. code:: bash + + med2image -i vol.nii -d out + + OR + + med2image -i file.dcm -d out Command line arguments ---------------------- @@ -91,11 +109,11 @@ Command line arguments for 2D input data. If a '-1' is sent, then convert *all* the slices. If an 'm' is specified, only convert the middle slice in an input volume. - + [-f|--frameToConvert ] In the case of 4D volume files, the volume (V) containing the - slice (z) index to convert. Ignored for 3D input data. If a '-1' is - sent, then convert *all* the frames. If an 'm' is specified, only + slice (z) index to convert. Ignored for 3D input data. If a '-1' is + sent, then convert *all* the frames. If an 'm' is specified, only convert the middle frame in the 4D input stack. [--showSlices] @@ -113,19 +131,38 @@ Command line arguments [-y|--synopsis] Show brief help. -NIfTI conversion ----------------- +NIfTI +----- +**NOTE:** One NIfTI (`.nii`) is one entire volume of multiple slices. + + So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) + +- The NIfTI input data can be in 2 forms: + - 3D : Single `.nii` volume which has multiple slices + - 4D : A directory with multiple `.nii` files (volumes) + +- The application understands both types of inputs. + +Pull NIfTI +~~~~~~~~~~ + +The inputFile should be a NIfTI volume of the format ``.nii`` + +- A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) + +- This repository can be cloned and used as an input volume. + +Convert NIfTI +~~~~~~~~~~~~~ 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 @@ -161,15 +198,11 @@ This will create the following files in out image-slice053.jpg Convert only a single slice -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mostly, you'll probably only want to convert the "middle" slice in a volume (for example to generate a representative thumbnail of the -volume). To do this, simply specify a m to --sliceToConvert - -``med2image -i input.nii -o input.jpg -s m`` - -or, again, slightly more verbosely and with an outputDirectory specifier +volume). To do this, simply specify a m to --sliceToConvert (or -s m) ``med2image -i input.nii -d out -o vol --outputFileType jpg --sliceToConvert m`` @@ -179,34 +212,60 @@ Alternatively a specific slice index can be converted. Use to convert only the 20th slice of the volume. -DICOM conversion ----------------- +DICOM +----- + +**NOTE:** One DICOM (`.dcm`) corresponds to one `.png` or `.jpg` file (slice) + +Pull DICOM +~~~~~~~~~~ + +The inputFile should be a DICOM file of the format ``.dcm`` + + +- A sample volume can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) + +- This repository can be cloned and used as an input volume. + +Convert DICOM +~~~~~~~~~~~~~ Convert a single DICOM file -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -To convert a single DICOM file called slice.dcm to slice.jpg, do: -``med2image -i slice.dcm -o slice.jpg`` +Mostly, you'll probably only want to convert the "middle" slice in a +DICOM directory (for example to generate a representative thumbnail of the +directory). To do this, simply specify a m to --sliceToConvert (or -s m) -which will create a single file, slice.jpg in the current directory. +``med2image -i slice.dcm -d out -o slice --outputFileType jpg --sliceToConvert m`` + +Alternatively a specific slice index can be converted. Use + +``med2image -i slice.dcm -d out -o slice --outputFileType jpg --sliceToConvert 20`` + +to convert only the 20th slice of the volume. + + +**Note:** If outputDir (-d) is not mentioned, the slice will get created in the current directory. Convert all DICOMS in a directory/series -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To convert all the DICOMS in a directory, simply specifiy a '-1' to the sliceIndex: ``med2image -i inputDir/slice.dcm -d outputDir -o slice.jpg -s -1`` -Note that this assumes all the DICOM files in the directory inputDir +**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. However, by passing a `--reslice` 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. @@ -214,3 +273,5 @@ 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. + +**NOTE:** In case of DICOM images, the `--reslice` option will work only if all slices in the directory are converted which means: ``--sliceToConvert -1`` \ No newline at end of file From d64469f944c7ec4efec6ef69c4a760c8800f7e86 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Tue, 19 May 2020 17:36:09 -0400 Subject: [PATCH 07/63] minor changes --- README.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0b25351..a42d0c6 100644 --- a/README.rst +++ b/README.rst @@ -247,7 +247,10 @@ Alternatively a specific slice index can be converted. Use to convert only the 20th slice of the volume. -**Note:** If outputDir (-d) is not mentioned, the slice will get created in the current directory. +**Note:** + +- If outputDir (-d) is not mentioned, the slice will get created in the current directory. +- if `--sliceToConvert` argument is not specified, then it converts all the `.dcm` files in the directory by default. Convert all DICOMS in a directory/series ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 06ace6f12038e34af40ba6c6c60c5ce8e31dee8a Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:06:02 -0400 Subject: [PATCH 08/63] Modified README.rst --- README.rst | 161 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 111 insertions(+), 50 deletions(-) diff --git a/README.rst b/README.rst index a42d0c6..abab036 100644 --- a/README.rst +++ b/README.rst @@ -21,11 +21,11 @@ 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 files) -- ``pydicom`` (to read DICOM files) -- ``matplotlib`` (to save data in various image formats) -- ``pillow`` (to save data in jpg format) +- ``pfmisc`` : (a general miscellaneous module for color support, etc) +- ``nibabel`` : (to read NIfTI files) +- ``pydicom`` : (to read DICOM files) +- ``matplotlib`` : (to save data in various image formats) +- ``pillow`` : (to save data in jpg format) Installation ~~~~~~~~~~~~ @@ -49,11 +49,9 @@ How to Use The med2image needs the following required arguments to run the application: -- -i|--inputFile - Input file to convert. Typically a DICOM file or a nifti volume. +- ``-i | --inputFile `` : Input file to convert. Typically a DICOM file or a nifti volume. -- -d|--outputDir - The directory to contain the converted output image files. +- ``-d | --outputDir :`` The directory to contain the converted output image files. .. code:: bash @@ -138,6 +136,7 @@ NIfTI So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) - The NIfTI input data can be in 2 forms: + - 3D : Single `.nii` volume which has multiple slices - 4D : A directory with multiple `.nii` files (volumes) @@ -148,13 +147,19 @@ Pull NIfTI The inputFile should be a NIfTI volume of the format ``.nii`` -- A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) +A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) -- This repository can be cloned and used as an input volume. +- Clone this repository (``SAG-anon-nii``) to your local computer. +- This directory contains a NIfTI volume with the name ``SAG-anon.nii``. Convert NIfTI ~~~~~~~~~~~~~ +**NOTE:** + +- If outputDir (-d) is not mentioned, the slice will get created in the current directory. +- if `--sliceToConvert` argument is not specified, then it converts all the slices of the ``.nii`` volume by default. + 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 @@ -164,38 +169,35 @@ index. In most cases, only a slice is required since most NIfTI data is 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 +To convert all slices in the input NIfTI volume ``SAG-anon-nii/SAG-anon.nii``, to save +the results in a directory called ``results``, to use as output the file stem +name ``sample``, and to save the result in ``jpg`` format, do: + +:: -``med2image -i vol.nii -d out -o image.jpg -s -1`` + med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample.jpg -s -1 or equivalently and more verbosely, :: - med2image --inputFile vol.nii --outputDir out \ - --outputFileStem image --outputFileType jpg \ + med2image --inputFile SAG-anon-nii/SAG-anon.nii --outputDir results \ + --outputFileStem sample --outputFileType jpg \ --sliceToConvert -1 -This will create the following files in out +This will create the following files in the ``result`` directory :: - image-slice000.jpg - image-slice001.jpg - image-slice002.jpg - image-slice003.jpg - image-slice004.jpg - image-slice005.jpg - image-slice006.jpg - image-slice007.jpg + results//sample-slice000.jpg + results//sample-slice001.jpg + results//sample-slice002.jpg + results//sample-slice003.jpg ... - image-slice049.jpg - image-slice050.jpg - image-slice051.jpg - image-slice052.jpg - image-slice053.jpg + results//sample-slice188.jpg + results//sample-slice189.jpg + results//sample-slice190.jpg + results//sample-slice191.jpg Convert only a single slice ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -204,14 +206,36 @@ Mostly, you'll probably only want to convert the "middle" slice in a volume (for example to generate a representative thumbnail of the volume). To do this, simply specify a m to --sliceToConvert (or -s m) -``med2image -i input.nii -d out -o vol --outputFileType jpg --sliceToConvert m`` +:: + + med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert m + +This will create the following files in the ``result`` directory + +:: + + results//sample-slice096.jpg Alternatively a specific slice index can be converted. Use -``med2image -i input.nii -d out -o vol --outputFileType jpg --sliceToConvert 20`` +:: + + med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert 20 to convert only the 20th slice of the volume. +This will create the following files in the ``result`` directory + +:: + + results//sample-slice020.jpg + +**NOTE:** + +- These samples below are run from within the current working directory which contains the ``SAG-anon-nii`` input data set directory. + +- If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments + DICOM ----- @@ -222,47 +246,84 @@ Pull DICOM The inputFile should be a DICOM file of the format ``.dcm`` +A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) -- A sample volume can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) - -- This repository can be cloned and used as an input volume. +- Clone this repository (``SAG-anon``) to your local computer. +- This directory contains multiple DICOM files/slices. Convert DICOM ~~~~~~~~~~~~~ +Convert all DICOMS in a directory/series +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To convert all the DICOMS in a directory, simply specifiy a '-1' to the +sliceIndex: + +:: + + med2image -i SAG-anon/any-slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert -1 + +This will create the following files in the ``result`` directory + +:: + + results//sample-slice000.jpg + results//sample-slice001.jpg + results//sample-slice002.jpg + results//sample-slice003.jpg + ... + results//sample-slice188.jpg + results//sample-slice189.jpg + results//sample-slice190.jpg + results//sample-slice191.jpg + +**NOTE:** + +- Even though any one ``.dcm`` from the directory is passed to the ``--inputFile`` argument, all the ``.dcm`` files/slices in the ``SAG-anon`` directory will be converted. + Convert a single DICOM file ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +**NOTE:** + +- These samples below are run from within the current working directory which contains the ``SAG-anon`` input data set directory. + +- If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments + Mostly, you'll probably only want to convert the "middle" slice in a DICOM directory (for example to generate a representative thumbnail of the directory). To do this, simply specify a m to --sliceToConvert (or -s m) -``med2image -i slice.dcm -d out -o slice --outputFileType jpg --sliceToConvert m`` +:: -Alternatively a specific slice index can be converted. Use + med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert m -``med2image -i slice.dcm -d out -o slice --outputFileType jpg --sliceToConvert 20`` +This will create the following files in the ``result`` directory -to convert only the 20th slice of the volume. +:: + results//sample-slice096.jpg -**Note:** +Alternatively a specific slice index can be converted. Use -- If outputDir (-d) is not mentioned, the slice will get created in the current directory. -- if `--sliceToConvert` argument is not specified, then it converts all the `.dcm` files in the directory by default. +:: -Convert all DICOMS in a directory/series -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert 20 -To convert all the DICOMS in a directory, simply specifiy a '-1' to the -sliceIndex: +to convert only the 20th slice of the volume. -``med2image -i inputDir/slice.dcm -d outputDir -o slice.jpg -s -1`` +This will create the following files in the ``result`` directory + +:: -**Note:** that this assumes all the DICOM files in the directory inputDir -belong to the same series. + results//sample-slice020.jpg +**NOTE:** + +- If outputDir (-d) is not mentioned, the slice will get created in the current directory. +- if `--sliceToConvert` argument is not specified, then it converts all the `.dcm` files in the directory by default. Multiple Direction Reslicing ---------------------------- From ac9248f10d66aab41b584627e20fee54316727f6 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:21:13 -0400 Subject: [PATCH 09/63] Modified README.rst --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index abab036..0d4db21 100644 --- a/README.rst +++ b/README.rst @@ -53,6 +53,8 @@ The med2image needs the following required arguments to run the application: - ``-d | --outputDir :`` The directory to contain the converted output image files. +**Example:** + .. code:: bash med2image -i vol.nii -d out @@ -61,6 +63,10 @@ The med2image needs the following required arguments to run the application: med2image -i file.dcm -d out +** The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* + +** More details about all required and optional Command Line Arguments can be found in the last section of this file.** + Command line arguments ---------------------- From 68cb142ad23e1cec177543ecc37dd33a5ceea080 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:22:18 -0400 Subject: [PATCH 10/63] Modified README.rst --- README.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 0d4db21..39c91b0 100644 --- a/README.rst +++ b/README.rst @@ -63,9 +63,11 @@ The med2image needs the following required arguments to run the application: med2image -i file.dcm -d out -** The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* +** NOTE:** -** More details about all required and optional Command Line Arguments can be found in the last section of this file.** +- The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* + +- More details about all required and optional Command Line Arguments can be found in the last section of this file. Command line arguments ---------------------- From fa5a8a4c57370e63cf5541de1bf81d5fca194256 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:23:00 -0400 Subject: [PATCH 11/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 39c91b0..910facb 100644 --- a/README.rst +++ b/README.rst @@ -63,7 +63,7 @@ The med2image needs the following required arguments to run the application: med2image -i file.dcm -d out -** NOTE:** +**NOTE:** - The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* From b25b8d2d0c70e61494b4e0de0682c5bd2d13d060 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:24:46 -0400 Subject: [PATCH 12/63] Modified README.rst --- README.rst | 140 ++++++++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/README.rst b/README.rst index 910facb..199f7d4 100644 --- a/README.rst +++ b/README.rst @@ -67,75 +67,7 @@ The med2image needs the following required arguments to run the application: - The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* -- More details about all required and optional Command Line Arguments can be found in the last section of this file. - -Command line arguments ----------------------- - -:: - - -i|--inputFile - Input file to convert. Typically a DICOM file or a nifti volume. - - [-d|--outputDir ] - The directory to contain the converted output image files. - - -o|--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 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 %inputFile is available to specify the input file that - was read (without extension). - - [-t|--outputFileType ] - The output file type. If different to extension, - will override extension in favour of . - - [-s|--sliceToConvert ] - In the case of volume files, the slice (z) index to convert. Ignored - for 2D input data. If a '-1' is sent, then convert *all* the slices. - If an 'm' is specified, only convert the middle slice in an input - volume. - - [-f|--frameToConvert ] - In the case of 4D volume files, the volume (V) containing the - slice (z) index to convert. Ignored for 3D input data. If a '-1' is - sent, then convert *all* the frames. If an 'm' is specified, only - convert the middle frame in the 4D input stack. - - [--showSlices] - If specified, render/show image slices as they are created. - - [--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 is subdivided into - 'slice' (k), 'row' (i), and 'col' (j) subdirectories. - - [-x|--man] - Show full help. - - [-y|--synopsis] - Show brief help. +- More details about all required and optional *Command Line Arguments* can be found in the last section of this file. NIfTI ----- @@ -346,4 +278,72 @@ and y correspond to planes normal to the row and column directions. Converted images are stored in subdirectories labeled x, y, and z. -**NOTE:** In case of DICOM images, the `--reslice` option will work only if all slices in the directory are converted which means: ``--sliceToConvert -1`` \ No newline at end of file +**NOTE:** In case of DICOM images, the `--reslice` option will work only if all slices in the directory are converted which means: ``--sliceToConvert -1`` + +Command line arguments +---------------------- + +:: + + -i|--inputFile + Input file to convert. Typically a DICOM file or a nifti volume. + + [-d|--outputDir ] + The directory to contain the converted output image files. + + -o|--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 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 %inputFile is available to specify the input file that + was read (without extension). + + [-t|--outputFileType ] + The output file type. If different to extension, + will override extension in favour of . + + [-s|--sliceToConvert ] + In the case of volume files, the slice (z) index to convert. Ignored + for 2D input data. If a '-1' is sent, then convert *all* the slices. + If an 'm' is specified, only convert the middle slice in an input + volume. + + [-f|--frameToConvert ] + In the case of 4D volume files, the volume (V) containing the + slice (z) index to convert. Ignored for 3D input data. If a '-1' is + sent, then convert *all* the frames. If an 'm' is specified, only + convert the middle frame in the 4D input stack. + + [--showSlices] + If specified, render/show image slices as they are created. + + [--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 is subdivided into + 'slice' (k), 'row' (i), and 'col' (j) subdirectories. + + [-x|--man] + Show full help. + + [-y|--synopsis] + Show brief help. From 9a7fb3f733a60a367c7bb4287f0f0a0740852c0d Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:28:13 -0400 Subject: [PATCH 13/63] Modified README.rst --- README.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 199f7d4..67dc8be 100644 --- a/README.rst +++ b/README.rst @@ -97,8 +97,8 @@ Convert NIfTI **NOTE:** -- If outputDir (-d) is not mentioned, the slice will get created in the current directory. -- if `--sliceToConvert` argument is not specified, then it converts all the slices of the ``.nii`` volume by default. +- If ``--outputDir (-d)`` is not mentioned, the slice will get created in the current directory. +- if ``--sliceToConvert`` argument is not specified, then it converts all the slices of the ``.nii`` volume by default. 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 @@ -184,7 +184,7 @@ DICOM Pull DICOM ~~~~~~~~~~ -The inputFile should be a DICOM file of the format ``.dcm`` +The ``inputFile`` should be a DICOM file of the format ``.dcm`` A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) @@ -194,6 +194,11 @@ A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (h Convert DICOM ~~~~~~~~~~~~~ +**NOTE:** + +- If ``--outputDir (-d)`` is not mentioned, the slice will get created in the current directory. +- if ``--sliceToConvert`` argument is not specified, then it converts all the `.dcm` files in the directory by default. + Convert all DICOMS in a directory/series ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -260,11 +265,6 @@ This will create the following files in the ``result`` directory results//sample-slice020.jpg -**NOTE:** - -- If outputDir (-d) is not mentioned, the slice will get created in the current directory. -- if `--sliceToConvert` argument is not specified, then it converts all the `.dcm` files in the directory by default. - Multiple Direction Reslicing ---------------------------- From fab48be7f0ffb613b5ca1f69767035e762b61e69 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:29:31 -0400 Subject: [PATCH 14/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 67dc8be..0103e5f 100644 --- a/README.rst +++ b/README.rst @@ -101,7 +101,7 @@ Convert NIfTI - if ``--sliceToConvert`` argument is not specified, then it converts all the slices of the ``.nii`` volume by default. 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 +a specific frame (``--frameToConvert``) 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. From 073a99cada5a47d33ae0b43ca5013747acef7430 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:32:19 -0400 Subject: [PATCH 15/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0103e5f..2844ca2 100644 --- a/README.rst +++ b/README.rst @@ -280,7 +280,7 @@ Converted images are stored in subdirectories labeled x, y, and z. **NOTE:** In case of DICOM images, the `--reslice` option will work only if all slices in the directory are converted which means: ``--sliceToConvert -1`` -Command line arguments +Command Line Arguments ---------------------- :: From aaad4097a6e5396725126f49af2d3bf1152c1c6f Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:38:30 -0400 Subject: [PATCH 16/63] Modified README.rst --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 2844ca2..753c0ee 100644 --- a/README.rst +++ b/README.rst @@ -113,13 +113,13 @@ To convert all slices in the input NIfTI volume ``SAG-anon-nii/SAG-anon.nii``, t the results in a directory called ``results``, to use as output the file stem name ``sample``, and to save the result in ``jpg`` format, do: -:: +.. code:: bash med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample.jpg -s -1 or equivalently and more verbosely, -:: +.. code:: bash med2image --inputFile SAG-anon-nii/SAG-anon.nii --outputDir results \ --outputFileStem sample --outputFileType jpg \ @@ -146,7 +146,7 @@ Mostly, you'll probably only want to convert the "middle" slice in a volume (for example to generate a representative thumbnail of the volume). To do this, simply specify a m to --sliceToConvert (or -s m) -:: +.. code:: bash med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert m @@ -158,7 +158,7 @@ This will create the following files in the ``result`` directory Alternatively a specific slice index can be converted. Use -:: +.. code:: bash med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert 20 @@ -205,7 +205,7 @@ Convert all DICOMS in a directory/series To convert all the DICOMS in a directory, simply specifiy a '-1' to the sliceIndex: -:: +.. code:: bash med2image -i SAG-anon/any-slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert -1 @@ -241,7 +241,7 @@ Mostly, you'll probably only want to convert the "middle" slice in a DICOM directory (for example to generate a representative thumbnail of the directory). To do this, simply specify a m to --sliceToConvert (or -s m) -:: +.. code:: bash med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert m @@ -253,7 +253,7 @@ This will create the following files in the ``result`` directory Alternatively a specific slice index can be converted. Use -:: +.. code:: bash med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert 20 From 5e1d0f97cdf43be3868335271f2438b92b2b3381 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:40:21 -0400 Subject: [PATCH 17/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 753c0ee..751aed7 100644 --- a/README.rst +++ b/README.rst @@ -73,7 +73,7 @@ NIfTI ----- **NOTE:** One NIfTI (`.nii`) is one entire volume of multiple slices. - So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) +So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) - The NIfTI input data can be in 2 forms: From f134e42e5e8b202391c0d198db07ce53a06f0e4d Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:43:07 -0400 Subject: [PATCH 18/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 751aed7..c350a1c 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ Should you get an error about `python3-tk` not installed, simply do (for example How to Use ---------- -The med2image needs the following required arguments to run the application: +The ``med2image`` needs the following required arguments to run the application: - ``-i | --inputFile `` : Input file to convert. Typically a DICOM file or a nifti volume. From 83157ceddbffda8d45e28265eeaa85e9362c68ed Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 15:43:44 -0400 Subject: [PATCH 19/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c350a1c..33a30ae 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ Should you get an error about `python3-tk` not installed, simply do (for example How to Use ---------- -The ``med2image`` needs the following required arguments to run the application: +``med2image`` needs the following required arguments to run the application: - ``-i | --inputFile `` : Input file to convert. Typically a DICOM file or a nifti volume. From 821d8553ac29c3c2eaa315c14894819d40489932 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 17:12:43 -0400 Subject: [PATCH 20/63] Modified README.rst --- README.rst | 86 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/README.rst b/README.rst index 33a30ae..9b25586 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,13 @@ The inputFile should be a NIfTI volume of the format ``.nii`` A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) - Clone this repository (``SAG-anon-nii``) to your local computer. -- This directory contains a NIfTI volume with the name ``SAG-anon.nii``. + +.. code:: bash + + git clone https://github.com/FNNDSC/SAG-anon-nii.git + +- This will create a folder called ``SAG-anon-nii`` in the current working directory. +- This directory will contain a NIfTI volume with the name ``SAG-anon.nii``. Convert NIfTI ~~~~~~~~~~~~~ @@ -105,39 +111,42 @@ a specific frame (``--frameToConvert``) can be specified in conjunction with a s 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. +- Create a folder called ``nifti-results`` in the current working directory which also contains the input data set ``SAG-anon-nii`` + +- We will be storing all results in subdirectories within this directory. All slices in a volume ^^^^^^^^^^^^^^^^^^^^^^ To convert all slices in the input NIfTI volume ``SAG-anon-nii/SAG-anon.nii``, to save -the results in a directory called ``results``, to use as output the file stem +the results in a sub-directory called ``all-slices`` within the directory ``nifti-results`` , to use as output the file stem name ``sample``, and to save the result in ``jpg`` format, do: .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample.jpg -s -1 + med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/all-slices -o sample.jpg -s -1 or equivalently and more verbosely, .. code:: bash - med2image --inputFile SAG-anon-nii/SAG-anon.nii --outputDir results \ + med2image --inputFile SAG-anon-nii/SAG-anon.nii --outputDir nifti-results/all-slices \ --outputFileStem sample --outputFileType jpg \ --sliceToConvert -1 -This will create the following files in the ``result`` directory +This will create the following files in the ``all-slices`` sub-directory within ``nifti-results`` directory :: - results//sample-slice000.jpg - results//sample-slice001.jpg - results//sample-slice002.jpg - results//sample-slice003.jpg + nifti-results/all-slices/sample-slice000.jpg + nifti-results/all-slices/sample-slice001.jpg + nifti-results/all-slices/sample-slice002.jpg + nifti-results/all-slices/sample-slice003.jpg ... - results//sample-slice188.jpg - results//sample-slice189.jpg - results//sample-slice190.jpg - results//sample-slice191.jpg + nifti-results/all-slices/sample-slice188.jpg + nifti-results/all-slices/sample-slice189.jpg + nifti-results/all-slices/sample-slice190.jpg + nifti-results/all-slices/sample-slice191.jpg Convert only a single slice ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,27 +157,27 @@ volume). To do this, simply specify a m to --sliceToConvert (or -s m) .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert m + med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/middle-slice -o sample --outputFileType jpg --sliceToConvert m -This will create the following files in the ``result`` directory +This will create the following files in the ``middle-slice`` sub-directory within ``nifti-results`` directory. :: - results//sample-slice096.jpg + nifti-results/middle-slice/sample-slice096.jpg Alternatively a specific slice index can be converted. Use .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d results -o sample --outputFileType jpg --sliceToConvert 20 + med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/specific-slice -o sample --outputFileType jpg --sliceToConvert 20 to convert only the 20th slice of the volume. -This will create the following files in the ``result`` directory +This will create the following files in the ``specific-slice`` sub-directory within ``nifti-results`` directory. :: - results//sample-slice020.jpg + nifti-results/specific-slice/sample-slice020.jpg **NOTE:** @@ -199,6 +208,12 @@ Convert DICOM - If ``--outputDir (-d)`` is not mentioned, the slice will get created in the current directory. - if ``--sliceToConvert`` argument is not specified, then it converts all the `.dcm` files in the directory by default. +**NOTE:** + +- Create a folder called ``dicom-results`` in the current working directory which also contains the input data set ``SAG-anon-nii`` + +- We will be storing all results in subdirectories within this directory. + Convert all DICOMS in a directory/series ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -207,21 +222,21 @@ sliceIndex: .. code:: bash - med2image -i SAG-anon/any-slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert -1 + med2image -i SAG-anon/any-slice-name.dcm -d dicom-results/all-slices -o sample --outputFileType jpg --sliceToConvert -1 -This will create the following files in the ``result`` directory +This will create the following files in the ``all-slices`` sub-directory within ``dicom-results`` directory. :: - results//sample-slice000.jpg - results//sample-slice001.jpg - results//sample-slice002.jpg - results//sample-slice003.jpg + dicom-results/all-slices/sample-slice000.jpg + dicom-results/all-slices/sample-slice001.jpg + dicom-results/all-slices/sample-slice002.jpg + dicom-results/all-slices/sample-slice003.jpg ... - results//sample-slice188.jpg - results//sample-slice189.jpg - results//sample-slice190.jpg - results//sample-slice191.jpg + dicom-results/all-slices/sample-slice188.jpg + dicom-results/all-slices/sample-slice189.jpg + dicom-results/all-slices/sample-slice190.jpg + dicom-results/all-slices/sample-slice191.jpg **NOTE:** @@ -243,27 +258,28 @@ directory). To do this, simply specify a m to --sliceToConvert (or -s m) .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert m + med2image -i SAG-anon/slice-name.dcm -d dicom-results/middle-slice -o sample --outputFileType jpg --sliceToConvert m -This will create the following files in the ``result`` directory +This will create the following files in the ``middle-slice`` sub-directory within ``dicom-results`` directory. :: - results//sample-slice096.jpg + dicom-results/middle-slice/sample-slice096.jpg + Alternatively a specific slice index can be converted. Use .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d results -o sample --outputFileType jpg --sliceToConvert 20 + med2image -i SAG-anon/slice-name.dcm -d dicom-results/specific-slice -o sample --outputFileType jpg --sliceToConvert 20 to convert only the 20th slice of the volume. -This will create the following files in the ``result`` directory +This will create the following files in the ``specific-slice`` sub-directory within ``dicom-results`` directory. :: - results//sample-slice020.jpg + dicom-results/specific-slice/sample-slice020.jpg Multiple Direction Reslicing ---------------------------- From 5d42e3f581bf2e81ec12ce2c148b4a1a78ee4be9 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Wed, 20 May 2020 17:14:49 -0400 Subject: [PATCH 21/63] Modified README.rst --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 9b25586..aaf0903 100644 --- a/README.rst +++ b/README.rst @@ -198,6 +198,12 @@ The ``inputFile`` should be a DICOM file of the format ``.dcm`` A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) - Clone this repository (``SAG-anon``) to your local computer. + +.. code:: bash + + git clone https://github.com/FNNDSC/SAG-anon.git + +- This will create a folder called ``SAG-anon`` in the current working directory. - This directory contains multiple DICOM files/slices. Convert DICOM From 04805afc76ddea8b8e1b2d02f0ccd96ffafb4b9a Mon Sep 17 00:00:00 2001 From: arushivyas Date: Thu, 21 May 2020 10:28:31 -0400 Subject: [PATCH 22/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index aaf0903..78360d6 100644 --- a/README.rst +++ b/README.rst @@ -153,7 +153,7 @@ Convert only a single slice Mostly, you'll probably only want to convert the "middle" slice in a volume (for example to generate a representative thumbnail of the -volume). To do this, simply specify a m to --sliceToConvert (or -s m) +volume). To do this, simply specify an ``m`` to ``--sliceToConvert`` (or ``-s m``) .. code:: bash From 12c8f95110f206d509873ca9eea1ee9d4496b138 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Thu, 21 May 2020 10:30:30 -0400 Subject: [PATCH 23/63] Modified README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 78360d6..759462e 100644 --- a/README.rst +++ b/README.rst @@ -216,7 +216,7 @@ Convert DICOM **NOTE:** -- Create a folder called ``dicom-results`` in the current working directory which also contains the input data set ``SAG-anon-nii`` +- Create a folder called ``dicom-results`` in the current working directory which also contains the input data set ``SAG-anon`` - We will be storing all results in subdirectories within this directory. From 28c2c8e1f3a0e09347c63b3899393448e854d3b0 Mon Sep 17 00:00:00 2001 From: arushivyas Date: Fri, 22 May 2020 09:29:30 -0400 Subject: [PATCH 24/63] Fixed bug for PatientName tag. --- README.rst | 4 ++++ bin/med2image | 2 ++ med2image/med2image.py | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 759462e..98648be 100644 --- a/README.rst +++ b/README.rst @@ -287,6 +287,10 @@ This will create the following files in the ``specific-slice`` sub-directory wit dicom-results/specific-slice/sample-slice020.jpg +Special Cases +^^^^^^^^^^^^^ + + Multiple Direction Reslicing ---------------------------- diff --git a/bin/med2image b/bin/med2image index 5789fc1..848dc9d 100755 --- a/bin/med2image +++ b/bin/med2image @@ -282,6 +282,8 @@ if args.man or args.synopsis: print(str_help) sys.exit(1) +# sys.exit(0) +# pudb.set_trace() # Create the object imgConverter = med2image.object_factoryCreate(args).C_convert diff --git a/med2image/med2image.py b/med2image/med2image.py index b396753..77b1d5a 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -180,6 +180,7 @@ def description(self, *args): @staticmethod def urlify(astr, astr_join = '_'): # Remove all non-word characters (everything except numbers and letters) + # pudb.set_trace() astr = re.sub(r"[^\w\s]", '', astr) # Replace all runs of whitespace with an underscore @@ -505,7 +506,8 @@ def __init__(self, **kwargs): str_fileName, str_ext = os.path.splitext(self.str_inputFile) str_fileComponent = str_fileName else: - str_fileComponent = eval('self._dcm.%s' % key) + # pudb.set_trace() + str_fileComponent = eval('str(self._dcm.%s)' % key) str_fileComponent = med2image.urlify(str_fileComponent) if not len(self.str_outputFileStem): self.str_outputFileStem = str_fileComponent From 16ff6a26e931f3c58f9c2c4d56dcccb9c5c94ecf Mon Sep 17 00:00:00 2001 From: arushivyas Date: Fri, 22 May 2020 11:04:18 -0400 Subject: [PATCH 25/63] Modified README.rst - Special Tags --- README.rst | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.rst b/README.rst index 98648be..7e18029 100644 --- a/README.rst +++ b/README.rst @@ -290,6 +290,43 @@ This will create the following files in the ``specific-slice`` sub-directory wit Special Cases ^^^^^^^^^^^^^ +For DICOM data, the 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 %PatientID`` + +will use the DICOM 'PatientID' to name the output file. Note +that special characters (like spaces) in the DICOM value are +replaced by underscores '_'. + +.. code:: bash + + med2image -i SAG-anon/slice-name.dcm -d dicom-results/tags -o %PatientID.jpg -s m + +This will create the following file in the ``tags`` sub-directory within ``dicom-results`` directory. + +.. code:: bash + + dicom-results/tags/1449c1d.jpg + +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. + +.. code:: bash + + med2image -i SAG-anon/slice-name.dcm -d dicom-results/tags -o %PatientName%PatientID%ProtocolName.jpg -s m + +This will create the following file in the ``tags`` sub-directory within ``dicom-results`` directory. + +.. code:: bash + + dicom-results/tags/anonymized-1449c1d-SAG_MPRAGE_220_FOV.jpg + Multiple Direction Reslicing ---------------------------- From 4b94a478adabc777ebfbfb8867e734ea936c640a Mon Sep 17 00:00:00 2001 From: arushivyas <62362207+arushivyas@users.noreply.github.com> Date: Tue, 26 May 2020 10:03:48 -0400 Subject: [PATCH 26/63] Update README.rst --- README.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.rst b/README.rst index 7e18029..7db3705 100644 --- a/README.rst +++ b/README.rst @@ -377,9 +377,6 @@ Command Line Arguments and the output filename will have each DICOM tag string as specified in order, connected with dashes. - A special %inputFile is available to specify the input file that - was read (without extension). - [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . From e2aa11bbac2be5fb2efaf785a933329d91f5e6da Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 26 May 2020 15:13:35 -0400 Subject: [PATCH 27/63] Update README.rst --- README.rst | 57 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 7db3705..bb7ae0d 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image -- 2.1.1 +med2image 2.1.1 ================== Quick Overview @@ -58,8 +58,10 @@ How to Use .. code:: bash med2image -i vol.nii -d out + +OR - OR +.. code:: bash med2image -i file.dcm -d out @@ -76,10 +78,8 @@ NIfTI So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) - The NIfTI input data can be in 2 forms: - - - 3D : Single `.nii` volume which has multiple slices - - 4D : A directory with multiple `.nii` files (volumes) - + - 3D : Single `.nii` volume which has multiple slices + - 4D : A directory with multiple `.nii` files (volumes) - The application understands both types of inputs. Pull NIfTI @@ -130,7 +130,8 @@ or equivalently and more verbosely, .. code:: bash - med2image --inputFile SAG-anon-nii/SAG-anon.nii --outputDir nifti-results/all-slices \ + med2image --inputFile SAG-anon-nii/SAG-anon.nii \ + --outputDir nifti-results/all-slices \ --outputFileStem sample --outputFileType jpg \ --sliceToConvert -1 @@ -157,7 +158,10 @@ volume). To do this, simply specify an ``m`` to ``--sliceToConvert`` (or ``-s m` .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/middle-slice -o sample --outputFileType jpg --sliceToConvert m + med2image -i SAG-anon-nii/SAG-anon.nii \ + -d nifti-results/middle-slice \ + -o sample --outputFileType jpg \ + --sliceToConvert m This will create the following files in the ``middle-slice`` sub-directory within ``nifti-results`` directory. @@ -228,7 +232,11 @@ sliceIndex: .. code:: bash - med2image -i SAG-anon/any-slice-name.dcm -d dicom-results/all-slices -o sample --outputFileType jpg --sliceToConvert -1 + med2image -i SAG-anon/any-slice-name.dcm \ + -d dicom-results/all-slices \ + -o sample \ + --outputFileType jpg \ + --sliceToConvert -1 This will create the following files in the ``all-slices`` sub-directory within ``dicom-results`` directory. @@ -258,13 +266,14 @@ Convert a single DICOM file - If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments -Mostly, you'll probably only want to convert the "middle" slice in a -DICOM directory (for example to generate a representative thumbnail of the -directory). To do this, simply specify a m to --sliceToConvert (or -s m) +Mostly, you'll probably only want to convert the "middle" slice in a DICOM directory (for example to generate a representative thumbnail of the directory). To do this, simply specify a `m` to --sliceToConvert (or `-s m`) .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d dicom-results/middle-slice -o sample --outputFileType jpg --sliceToConvert m + med2image -i SAG-anon/slice-name.dcm \ + -d dicom-results/middle-slice \ + -o sample --outputFileType jpg \ + --sliceToConvert m This will create the following files in the ``middle-slice`` sub-directory within ``dicom-results`` directory. @@ -277,7 +286,10 @@ Alternatively a specific slice index can be converted. Use .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d dicom-results/specific-slice -o sample --outputFileType jpg --sliceToConvert 20 + med2image -i SAG-anon/slice-name.dcm \ + -d dicom-results/specific-slice \ + -o sample --outputFileType jpg \ + --sliceToConvert 20 to convert only the 20th slice of the volume. @@ -290,19 +302,17 @@ This will create the following files in the ``specific-slice`` sub-directory wit Special Cases ^^^^^^^^^^^^^ -For DICOM data, the 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 +For DICOM data, the 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 %PatientID`` -will use the DICOM 'PatientID' to name the output file. Note -that special characters (like spaces) in the DICOM value are -replaced by underscores '_'. +will use the DICOM 'PatientID' to name the output file. Note that special characters (like spaces) in the DICOM value are replaced by underscores '_'. .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d dicom-results/tags -o %PatientID.jpg -s m + med2image -i SAG-anon/slice-name.dcm \ + -d dicom-results/tags \ + -o %PatientID.jpg -s m This will create the following file in the ``tags`` sub-directory within ``dicom-results`` directory. @@ -319,7 +329,10 @@ specified in order, connected with dashes. .. code:: bash - med2image -i SAG-anon/slice-name.dcm -d dicom-results/tags -o %PatientName%PatientID%ProtocolName.jpg -s m + med2image -i SAG-anon/slice-name.dcm \ + -d dicom-results/tags \ + -o %PatientName%PatientID%ProtocolName.jpg \ + -s m This will create the following file in the ``tags`` sub-directory within ``dicom-results`` directory. From 427bcf3b759f0d81d30abcae6a77a7c59842ba58 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 26 May 2020 17:59:25 -0400 Subject: [PATCH 28/63] Update to 2.2.0 and push to PyPI --- README.rst | 6 +++++- bin/med2image | 27 ++++++++++++++++----------- setup.py | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index bb7ae0d..1c47a93 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.1.1 +med2image 2.2.0 ================== Quick Overview @@ -364,6 +364,10 @@ Command Line Arguments -i|--inputFile Input file to convert. Typically a DICOM file or a nifti volume. + [-I|--inputDir ] + If specified, a directory containing the . In this case + should be specified as relative to . + [-d|--outputDir ] The directory to contain the converted output image files. diff --git a/bin/med2image b/bin/med2image index 848dc9d..44ac875 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,17 +21,17 @@ from pfmisc._colors import Colors import pudb -str_version = "2.1.1" +str_version = "2.2.0" str_desc = Colors.CYAN + """ - _ _____ _ - | |/ __ \(_) - _ __ ___ ___ __| |`' / /' _ _ __ ___ __ _ __ _ ___ + _ _____ _ + | |/ __ \(_) + _ __ ___ ___ __| |`' / /' _ _ __ ___ __ _ __ _ ___ | '_ ` _ \ / _ \/ _` | / / | | '_ ` _ \ / _` |/ _` |/ _ \\ | | | | | | __/ (_| |./ /___| | | | | | | (_| | (_| | __/ |_| |_| |_|\___|\__,_|\_____/|_|_| |_| |_|\__,_|\__, |\___| - __/ | - |___/ + __/ | + |___/ med(ical image)2image @@ -59,6 +59,7 @@ def synopsis(ab_shortOnly=False): %s \\ -i|--input \\ + [-I|--inputDir ] \\ [-d|--outputDir ] \\ -o|--output \\ [-t|--outputFileType ] \\ @@ -89,6 +90,10 @@ def synopsis(ab_shortOnly=False): -i|--inputFile Input file to convert. Typically a DICOM file or a nifti volume. + [-I|--inputDir ] + If specified, a directory containing the . In this case + should be specified as relative to . + [-d|--outputDir ] The directory to contain the converted output image files. @@ -100,19 +105,19 @@ def synopsis(ab_shortOnly=False): SPECIAL CASES: For DICOM data, the 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 + 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 + 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 + and the output filename will have each DICOM tag string as specified in order, connected with dashes. A special %%inputFile is available to specify the input file that @@ -136,9 +141,9 @@ def synopsis(ab_shortOnly=False): [--showSlices] If specified, render/show image slices as they are created. - + [--func ] - Apply the specified transformation function before saving. Currently + Apply the specified transformation function before saving. Currently support functions: * invertIntensities diff --git a/setup.py b/setup.py index 1a17323..e6ed88d 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.1.1', + version = '2.2.0', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From ff705b6057e6826ea96ebf5365be56e027e5c797 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 26 May 2020 18:02:13 -0400 Subject: [PATCH 29/63] Update README.rst --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 1c47a93..47b26a6 100644 --- a/README.rst +++ b/README.rst @@ -173,7 +173,11 @@ Alternatively a specific slice index can be converted. Use .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/specific-slice -o sample --outputFileType jpg --sliceToConvert 20 + med2image -i SAG-anon-nii/SAG-anon.nii \ + -d nifti-results/specific-slice \ + -o sample \ + --outputFileType jpg \ + --sliceToConvert 20 to convert only the 20th slice of the volume. From 751ec7cef379af39ab216d8de92b2771e00f15cb Mon Sep 17 00:00:00 2001 From: arushivyas <62362207+arushivyas@users.noreply.github.com> Date: Wed, 27 May 2020 08:55:44 -0400 Subject: [PATCH 30/63] Update med2image Synopsis --- bin/med2image | 3 --- 1 file changed, 3 deletions(-) diff --git a/bin/med2image b/bin/med2image index 44ac875..0658dbe 100755 --- a/bin/med2image +++ b/bin/med2image @@ -120,9 +120,6 @@ def synopsis(ab_shortOnly=False): and the output filename will have each DICOM tag string as specified in order, connected with dashes. - A special %%inputFile is available to specify the input file that - was read (without extension). - [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . From 21174c6ca7084e43847bc45f689600b6196a53ea Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:10:04 -0400 Subject: [PATCH 31/63] Update README.rst --- README.rst | 193 ++++++++++++++++++++++++++--------------------------- 1 file changed, 94 insertions(+), 99 deletions(-) diff --git a/README.rst b/README.rst index 47b26a6..f4ce20d 100644 --- a/README.rst +++ b/README.rst @@ -4,34 +4,32 @@ med2image 2.2.0 Quick Overview -------------- -- Convert DICOM or NIfTI to jpg or png +- Convert ``DICOM`` or ``NIfTI`` inputs to ``jpg`` or ``png`` outputs. Overview -------- -``med2image`` is a simple Python3 utility that converts medical image -formatted files to more visual friendly ones, such as png and jpg. +``med2image`` is a simple Python3 utility that converts medical image formatted files (such as ``DICOM`` and ``NifTI``) 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. +Currently, ``NIfTI`` and ``DICOM`` input formats are understood, while any graphical output type that is supported by matplotlib can be generated. + +At present ``med2image`` does not convert ``DICOM`` to ``NifTI``, but this is planned for a future release. Dependencies ------------ -Make sure that the following dependencies are installed on your host -system (or even better, a python3 virtual env): +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 files) - ``pydicom`` : (to read DICOM files) - ``matplotlib`` : (to save data in various image formats) -- ``pillow`` : (to save data in jpg format) +- ``pillow`` : (to save data in ``jpg`` format) Installation ~~~~~~~~~~~~ -The best method of installing this script and all of its dependencies is -by fetching it from PyPI +The best method of installing this script and all of its dependencies is by fetching it from `PyPI `_. .. code:: bash @@ -47,7 +45,7 @@ Should you get an error about `python3-tk` not installed, simply do (for example How to Use ---------- -``med2image`` needs the following required arguments to run the application: +``med2image`` needs at a minimum the following required command line arguments: - ``-i | --inputFile `` : Input file to convert. Typically a DICOM file or a nifti volume. @@ -57,37 +55,43 @@ How to Use .. code:: bash + # Convert a NifTI file 'vol.nii' to JPEG and store + # the results in a dirctory called 'out'. + # The 'out' dir will contain a set of JPEG + # images of form 'output-sliceXXX.jpg'. + med2image -i vol.nii -d out -OR + OR .. code:: bash + # Convert a DICOM file 'file.dcm' to JPEG and store + # the results in a dirctory called 'out'. + # The 'out' dir will contain a set of JPEG + # images of form 'output-sliceXXX.jpg'. + + # NOTE! If the directory containing 'file.dcm' contains + # multiple DICOM files, *ALL* of these will be converted + # to JPEG. See later for only converting a *single* + # DICOM file. + med2image -i file.dcm -d out + +``NIfTI`` details +----------------- -**NOTE:** - -- The following 2 sections: NIfTI and DICOM explain how to run the ``med2image`` app using different *Command Line Arguments* - -- More details about all required and optional *Command Line Arguments* can be found in the last section of this file. - -NIfTI ------ -**NOTE:** One NIfTI (`.nii`) is one entire volume of multiple slices. +**NOTE:** ``NifTI`` is typically a *volume* format. One ``NIfTI`` (``.nii``) volume contains multiple *slices*. Converting a ``NifTI`` volume results in multiple `.jpg` or `.png` results. -So, one `.nii` corresponds to multiple `.png` or `.jpg` file (slices) - -- The NIfTI input data can be in 2 forms: +- ``NIfTI`` input data can be in 2 forms: - 3D : Single `.nii` volume which has multiple slices - 4D : A directory with multiple `.nii` files (volumes) -- The application understands both types of inputs. +- ``med2image`` understands both types of inputs. -Pull NIfTI -~~~~~~~~~~ - -The inputFile should be a NIfTI volume of the format ``.nii`` +Pull ``NIfTI`` +~~~~~~~~~~~~~ -A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) +The inputFile should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) - Clone this repository (``SAG-anon-nii``) to your local computer. @@ -98,33 +102,32 @@ A sample volume can be found on Github at ``FNNDSC/SAG-anon-nii``. (https://gith - This will create a folder called ``SAG-anon-nii`` in the current working directory. - This directory will contain a NIfTI volume with the name ``SAG-anon.nii``. -Convert NIfTI +Convert ``NIfTI`` ~~~~~~~~~~~~~ **NOTE:** -- If ``--outputDir (-d)`` is not mentioned, the slice will get created in the current directory. -- if ``--sliceToConvert`` argument is not specified, then it converts all the slices of the ``.nii`` volume by default. +- If ``--outputDir | -d`` is not provided, outputs are created in the *current* directory. +- if ``--sliceToConvert`` is not provided, *all* the slices of the ``.nii`` volume are converted. -Both 3D and 4D NIfTI input data are understood. In the case of 4D NIfTI, -a specific frame (``--frameToConvert``) 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. +Both 3D and 4D ``NIfTI`` input data are understood. In the case of 4D ``NIfTI``, a specific frame (``--frameToConvert``) can be additionally provided in conjunction with a specific slice index. Conversion options include: -- Create a folder called ``nifti-results`` in the current working directory which also contains the input data set ``SAG-anon-nii`` +- *all* slices (default) +- *middle* slice only, with the CLI ``--sliceToConvert m`` +- *someSpecificSlice*, with the CLI ``--sliceToConvert `` -- We will be storing all results in subdirectories within this directory. +CASE 1: All slices in a volume +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -All slices in a volume -^^^^^^^^^^^^^^^^^^^^^^ +Now, let's convert all slices in the input ``NIfTI`` volume ``SAG-anon.nii``, and save the results to a nested subdir ``nifti-results/all-slices``. We'll use as output file name stem ``sample`` and convert to ``jpg``. -To convert all slices in the input NIfTI volume ``SAG-anon-nii/SAG-anon.nii``, to save -the results in a sub-directory called ``all-slices`` within the directory ``nifti-results`` , to use as output the file stem -name ``sample``, and to save the result in ``jpg`` format, do: +Assuming you have cloned the ``SAG-anon-nii`` repo and assuming that you have ``med2image`` on your UNIX shell path, .. code:: bash - med2image -i SAG-anon-nii/SAG-anon.nii -d nifti-results/all-slices -o sample.jpg -s -1 + med2image -i SAG-anon-nii/SAG-anon.nii \ + -d nifti-results/all-slices \ + -o sample.jpg -s -1 or equivalently and more verbosely, @@ -135,7 +138,7 @@ or equivalently and more verbosely, --outputFileStem sample --outputFileType jpg \ --sliceToConvert -1 -This will create the following files in the ``all-slices`` sub-directory within ``nifti-results`` directory +This will create the following files in the ``all-slices`` sub-directory within ``nifti-results`` directory. Note that even if the nested output directory structure does not exist, ``med2image`` will create it for you. :: @@ -149,12 +152,10 @@ This will create the following files in the ``all-slices`` sub-directory within nifti-results/all-slices/sample-slice190.jpg nifti-results/all-slices/sample-slice191.jpg -Convert only a single slice -^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Case 2: Convert only a single slice +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Mostly, you'll probably only want to convert the "middle" slice in a -volume (for example to generate a representative thumbnail of the -volume). To do this, simply specify an ``m`` to ``--sliceToConvert`` (or ``-s m``) +Often times, you might only want to convert the "middle" slice in a volume (for example to generate a representative thumbnail of the volume). To do this, simply specify an ``m`` to ``--sliceToConvert`` (or ``-s m``): .. code:: bash @@ -163,7 +164,7 @@ volume). To do this, simply specify an ``m`` to ``--sliceToConvert`` (or ``-s m` -o sample --outputFileType jpg \ --sliceToConvert m -This will create the following files in the ``middle-slice`` sub-directory within ``nifti-results`` directory. +This will create a single file in the ``middle-slice`` sub-directory within ``nifti-results`` directory. :: @@ -181,7 +182,7 @@ Alternatively a specific slice index can be converted. Use to convert only the 20th slice of the volume. -This will create the following files in the ``specific-slice`` sub-directory within ``nifti-results`` directory. +This will create a single output file in the ``specific-slice`` sub-directory within ``nifti-results`` directory. :: @@ -193,17 +194,17 @@ This will create the following files in the ``specific-slice`` sub-directory wit - If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments -DICOM ------ +``DICOM`` +--------- -**NOTE:** One DICOM (`.dcm`) corresponds to one `.png` or `.jpg` file (slice) +**NOTE:** One DICOM (`.dcm`) file typically corresponds to one `.png` or `.jpg` file (slice). Pull DICOM ~~~~~~~~~~ -The ``inputFile`` should be a DICOM file of the format ``.dcm`` +The ``inputFile`` should be a ``DICOM`` file usually with extension ``.dcm`` -A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) +We provide a sample directory of ``.dcm`` images here ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) - Clone this repository (``SAG-anon``) to your local computer. @@ -214,25 +215,19 @@ A sample directory of ``.dcm`` can be found on Github at ``FNNDSC/SAG-anon``. (h - This will create a folder called ``SAG-anon`` in the current working directory. - This directory contains multiple DICOM files/slices. -Convert DICOM -~~~~~~~~~~~~~ +Convert ``DICOM`` +~~~~~~~~~~~~~~~~~ **NOTE:** -- If ``--outputDir (-d)`` is not mentioned, the slice will get created in the current directory. -- if ``--sliceToConvert`` argument is not specified, then it converts all the `.dcm` files in the directory by default. - -**NOTE:** +- If ``--outputDir | -d`` is not provided, any output(s) are created in the current directory. +- if ``--sliceToConvert`` argument is not specified and if mutiple ``dcm`` files are contained in the input directory with the ``DICOM`` input, then all the ``.dcm`` files are converted. -- Create a folder called ``dicom-results`` in the current working directory which also contains the input data set ``SAG-anon`` - -- We will be storing all results in subdirectories within this directory. Convert all DICOMS in a directory/series ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -To convert all the DICOMS in a directory, simply specifiy a '-1' to the -sliceIndex: +To convert all the ``DICOM``S in a directory, simply specify either ``--sliceToConvert -1`` (or just leave out the argument/value pair completely): .. code:: bash @@ -242,7 +237,15 @@ sliceIndex: --outputFileType jpg \ --sliceToConvert -1 -This will create the following files in the ``all-slices`` sub-directory within ``dicom-results`` directory. + # OR equivalently + + med2image -i SAG-anon/any-slice-name.dcm \ + -d dicom-results/all-slices \ + -o sample \ + --outputFileType jpg + + +This will create the following files in the ``dicom-results/all-slices``: :: @@ -256,19 +259,8 @@ This will create the following files in the ``all-slices`` sub-directory within dicom-results/all-slices/sample-slice190.jpg dicom-results/all-slices/sample-slice191.jpg -**NOTE:** - -- Even though any one ``.dcm`` from the directory is passed to the ``--inputFile`` argument, all the ``.dcm`` files/slices in the ``SAG-anon`` directory will be converted. - -Convert a single DICOM file -^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -**NOTE:** - -- These samples below are run from within the current working directory which contains the ``SAG-anon`` input data set directory. - -- If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments - +Convert a single ``DICOM`` file +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mostly, you'll probably only want to convert the "middle" slice in a DICOM directory (for example to generate a representative thumbnail of the directory). To do this, simply specify a `m` to --sliceToConvert (or `-s m`) @@ -279,7 +271,7 @@ Mostly, you'll probably only want to convert the "middle" slice in a DICOM direc -o sample --outputFileType jpg \ --sliceToConvert m -This will create the following files in the ``middle-slice`` sub-directory within ``dicom-results`` directory. +This will create the following file in the ``middle-slice`` sub-directory within ``dicom-results`` directory. :: @@ -295,9 +287,7 @@ Alternatively a specific slice index can be converted. Use -o sample --outputFileType jpg \ --sliceToConvert 20 -to convert only the 20th slice of the volume. - -This will create the following files in the ``specific-slice`` sub-directory within ``dicom-results`` directory. +to convert only the 20th slice of the volume and create the following file in the ``specific-slice`` sub-directory within ``dicom-results`` directory. :: @@ -306,11 +296,11 @@ This will create the following files in the ``specific-slice`` sub-directory wit Special Cases ^^^^^^^^^^^^^ -For DICOM data, the 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 +For ``DICOM`` data, the can optionally 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 %PatientID`` -will use the DICOM 'PatientID' to name the output file. Note that special characters (like spaces) in the DICOM value are replaced by underscores '_'. +will use the ``DICOM`` ``PatientID`` to name the output file. Note that special characters (like spaces) in the DICOM value are replaced by underscores '_'. .. code:: bash @@ -328,8 +318,7 @@ 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. +and the output filename will have each DICOM tag string as specified in order, connected with dashes. .. code:: bash @@ -348,17 +337,23 @@ This will create the following file in the ``tags`` sub-directory within ``dicom Multiple Direction Reslicing ---------------------------- -By default, only the slice (or slices) in the acquisition direction are -converted. However, by passing a `--reslice` 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. +By default, only the slice (or slices) in the acquisition direction are converted. However, by passing a `--reslice` 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``. -The z direction is the original acquistion (slice) direction, while x -and y correspond to planes normal to the row and column directions. +**NOTE:** No interpolation in the ``x`` and ``y`` directions is performed. This often results in ugly images! -Converted images are stored in subdirectories labeled x, y, and z. +**NOTE:** In case of ``DICOM`` images, the `--reslice` option will work only if all slices in the directory are converted, i.e. converting with ``--sliceToConvert -1`` -**NOTE:** In case of DICOM images, the `--reslice` option will work only if all slices in the directory are converted which means: ``--sliceToConvert -1`` +Special Operations +------------------ + +``med2image`` also supports some very basic image processing (currently in their infancy) through a ``--func ]`` CLI, which applies some canned transformation on the image. Currently supported is + +:: + --func invertIntensities + +which simply inverts the contrast intensity of the source image. Additional functions are planned for future releases. Command Line Arguments ---------------------- From f9bdd1cb416cbaf192aab7850ddbb79d396742fd Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:13:35 -0400 Subject: [PATCH 32/63] Update README.rst --- README.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index f4ce20d..9e0eed9 100644 --- a/README.rst +++ b/README.rst @@ -9,7 +9,7 @@ Quick Overview Overview -------- -``med2image`` is a simple Python3 utility that converts medical image formatted files (such as ``DICOM`` and ``NifTI``) to more visual friendly ones, such as ``png`` and ``jpg``. +``med2image`` is a simple Python3 utility that converts medical image formatted files (such as ``DICOM`` and ``NifTI``) to more web 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. @@ -18,7 +18,7 @@ At present ``med2image`` does not convert ``DICOM`` to ``NifTI``, but this is pl Dependencies ------------ -Make sure that the following dependencies are installed on your host system (or even better, a python3 virtual env): +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 files) @@ -47,7 +47,7 @@ How to Use ``med2image`` needs at a minimum the following required command line arguments: -- ``-i | --inputFile `` : Input file to convert. Typically a DICOM file or a nifti volume. +- ``-i | --inputFile `` : Input file to convert. Typically a ``DICOM`` file or a ``NifTI`` volume. - ``-d | --outputDir :`` The directory to contain the converted output image files. @@ -62,8 +62,6 @@ How to Use med2image -i vol.nii -d out - OR - .. code:: bash # Convert a DICOM file 'file.dcm' to JPEG and store @@ -81,11 +79,11 @@ How to Use ``NIfTI`` details ----------------- -**NOTE:** ``NifTI`` is typically a *volume* format. One ``NIfTI`` (``.nii``) volume contains multiple *slices*. Converting a ``NifTI`` volume results in multiple `.jpg` or `.png` results. +**NOTE:** ``NifTI`` is typically a *volume* format. One ``NIfTI`` (``.nii``) volume contains multiple *slices*. Converting a ``NifTI`` volume results in multiple ``.jpg`` or ``.png`` results. - ``NIfTI`` input data can be in 2 forms: - - 3D : Single `.nii` volume which has multiple slices - - 4D : A directory with multiple `.nii` files (volumes) + - 3D : The ``.nii`` volume contains multiple 2D slices + - 4D : The ``.nii`` file contains multiple 3D volumes that each contain multiple 2D slices - ``med2image`` understands both types of inputs. Pull ``NIfTI`` From 5d173e43cbeab87f93fc7e17fe8bdcf671d078e8 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:15:27 -0400 Subject: [PATCH 33/63] Update README.rst --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 9e0eed9..070ec78 100644 --- a/README.rst +++ b/README.rst @@ -82,8 +82,11 @@ How to Use **NOTE:** ``NifTI`` is typically a *volume* format. One ``NIfTI`` (``.nii``) volume contains multiple *slices*. Converting a ``NifTI`` volume results in multiple ``.jpg`` or ``.png`` results. - ``NIfTI`` input data can be in 2 forms: + - 3D : The ``.nii`` volume contains multiple 2D slices + - 4D : The ``.nii`` file contains multiple 3D volumes that each contain multiple 2D slices + - ``med2image`` understands both types of inputs. Pull ``NIfTI`` From 3699aa04cce2df4f7abbde95412a12248ee9bc8e Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:17:20 -0400 Subject: [PATCH 34/63] Update README.rst --- README.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 070ec78..a2f159b 100644 --- a/README.rst +++ b/README.rst @@ -92,7 +92,7 @@ How to Use Pull ``NIfTI`` ~~~~~~~~~~~~~ -The inputFile should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here ``FNNDSC/SAG-anon-nii``. (https://github.com/FNNDSC/SAG-anon-nii.git) +The inputFile should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here https://github.com/FNNDSC/SAG-anon-nii.git - Clone this repository (``SAG-anon-nii``) to your local computer. @@ -100,9 +100,6 @@ The inputFile should be a ``NIfTI`` volume with extension ``.nii``. We provide a git clone https://github.com/FNNDSC/SAG-anon-nii.git -- This will create a folder called ``SAG-anon-nii`` in the current working directory. -- This directory will contain a NIfTI volume with the name ``SAG-anon.nii``. - Convert ``NIfTI`` ~~~~~~~~~~~~~ From b04c0557fd803c3f225f71d442679d822bfd14c4 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:26:20 -0400 Subject: [PATCH 35/63] Update README.rst --- README.rst | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index a2f159b..ff9c67e 100644 --- a/README.rst +++ b/README.rst @@ -136,7 +136,7 @@ or equivalently and more verbosely, --outputFileStem sample --outputFileType jpg \ --sliceToConvert -1 -This will create the following files in the ``all-slices`` sub-directory within ``nifti-results`` directory. Note that even if the nested output directory structure does not exist, ``med2image`` will create it for you. +resulting in :: @@ -150,6 +150,8 @@ This will create the following files in the ``all-slices`` sub-directory within nifti-results/all-slices/sample-slice190.jpg nifti-results/all-slices/sample-slice191.jpg +Note that even if the nested output directory structure does not exist, ``med2image`` will create it for you. + Case 2: Convert only a single slice ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -162,7 +164,7 @@ Often times, you might only want to convert the "middle" slice in a volume (for -o sample --outputFileType jpg \ --sliceToConvert m -This will create a single file in the ``middle-slice`` sub-directory within ``nifti-results`` directory. +resulting in :: @@ -180,18 +182,12 @@ Alternatively a specific slice index can be converted. Use to convert only the 20th slice of the volume. -This will create a single output file in the ``specific-slice`` sub-directory within ``nifti-results`` directory. +resulting in :: nifti-results/specific-slice/sample-slice020.jpg -**NOTE:** - -- These samples below are run from within the current working directory which contains the ``SAG-anon-nii`` input data set directory. - -- If you are running the application from another working directory, make sure you provide the correct path for the ``--inputFile`` and ``--outputDir`` arguments - ``DICOM`` --------- @@ -210,9 +206,6 @@ We provide a sample directory of ``.dcm`` images here ``FNNDSC/SAG-anon``. (http git clone https://github.com/FNNDSC/SAG-anon.git -- This will create a folder called ``SAG-anon`` in the current working directory. -- This directory contains multiple DICOM files/slices. - Convert ``DICOM`` ~~~~~~~~~~~~~~~~~ @@ -243,7 +236,7 @@ To convert all the ``DICOM``S in a directory, simply specify either ``--sliceToC --outputFileType jpg -This will create the following files in the ``dicom-results/all-slices``: +resulting in :: @@ -269,7 +262,7 @@ Mostly, you'll probably only want to convert the "middle" slice in a DICOM direc -o sample --outputFileType jpg \ --sliceToConvert m -This will create the following file in the ``middle-slice`` sub-directory within ``dicom-results`` directory. +resulting in :: @@ -285,7 +278,7 @@ Alternatively a specific slice index can be converted. Use -o sample --outputFileType jpg \ --sliceToConvert 20 -to convert only the 20th slice of the volume and create the following file in the ``specific-slice`` sub-directory within ``dicom-results`` directory. +resulting in :: @@ -339,14 +332,14 @@ By default, only the slice (or slices) in the acquisition direction are converte 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``. -**NOTE:** No interpolation in the ``x`` and ``y`` directions is performed. This often results in ugly images! +No interpolation in the ``x`` and ``y`` directions is performed. This often results in ugly images! **NOTE:** In case of ``DICOM`` images, the `--reslice` option will work only if all slices in the directory are converted, i.e. converting with ``--sliceToConvert -1`` Special Operations ------------------ -``med2image`` also supports some very basic image processing (currently in their infancy) through a ``--func ]`` CLI, which applies some canned transformation on the image. Currently supported is +``med2image`` also supports some very basic image processing through a ``--func `` CLI, which applies some canned transformation on the image. Currently supported is :: --func invertIntensities From 9edc0258723348a022c930908477c301c4e2aca9 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:28:48 -0400 Subject: [PATCH 36/63] Update README.rst --- README.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ff9c67e..14694e2 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,11 @@ Make sure that the following dependencies are installed on your host system (or - ``matplotlib`` : (to save data in various image formats) - ``pillow`` : (to save data in ``jpg`` format) +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 ~~~~~~~~~~~~ @@ -35,7 +40,7 @@ The best method of installing this script and all of its dependencies is by fetc pip3 install med2image -Should you get an error about `python3-tk` not installed, simply do (for example on Ubuntu): +Should you get an error about ``python3-tk`` not installed, simply do (for example on Ubuntu): .. code:: bash From 311a777cf0d2fad7ad49c453d770cdc3a69e1b6a Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:29:42 -0400 Subject: [PATCH 37/63] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 14694e2..54442e0 100644 --- a/README.rst +++ b/README.rst @@ -97,7 +97,7 @@ How to Use Pull ``NIfTI`` ~~~~~~~~~~~~~ -The inputFile should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here https://github.com/FNNDSC/SAG-anon-nii.git +The input should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here https://github.com/FNNDSC/SAG-anon-nii.git - Clone this repository (``SAG-anon-nii``) to your local computer. From abe34622a090bd8c55d1262adafef99fb73436c3 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:41:54 -0400 Subject: [PATCH 38/63] Update README.rst --- README.rst | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 54442e0..f495172 100644 --- a/README.rst +++ b/README.rst @@ -196,12 +196,12 @@ resulting in ``DICOM`` --------- -**NOTE:** One DICOM (`.dcm`) file typically corresponds to one `.png` or `.jpg` file (slice). +**NOTE:** One ``DICOM`` (``.dcm``) file typically corresponds to one ``.png`` or ``.jpg`` file (slice). Pull DICOM ~~~~~~~~~~ -The ``inputFile`` should be a ``DICOM`` file usually with extension ``.dcm`` +The input should be a ``DICOM`` file usually with extension ``.dcm`` We provide a sample directory of ``.dcm`` images here ``FNNDSC/SAG-anon``. (https://github.com/FNNDSC/SAG-anon.git) @@ -227,7 +227,7 @@ To convert all the ``DICOM``S in a directory, simply specify either ``--sliceToC .. code:: bash - med2image -i SAG-anon/any-slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/all-slices \ -o sample \ --outputFileType jpg \ @@ -235,7 +235,7 @@ To convert all the ``DICOM``S in a directory, simply specify either ``--sliceToC # OR equivalently - med2image -i SAG-anon/any-slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/all-slices \ -o sample \ --outputFileType jpg @@ -262,7 +262,7 @@ Mostly, you'll probably only want to convert the "middle" slice in a DICOM direc .. code:: bash - med2image -i SAG-anon/slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/middle-slice \ -o sample --outputFileType jpg \ --sliceToConvert m @@ -271,14 +271,15 @@ resulting in :: - dicom-results/middle-slice/sample-slice096.jpg + dicom-results/middle-slice/sample.jpg +Note that even though the first slice in the ``SAG-anon`` directory was supplied to the script, ``med2image`` nonetheless found and converted the middle slice in the directory. Alternatively a specific slice index can be converted. Use .. code:: bash - med2image -i SAG-anon/slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/specific-slice \ -o sample --outputFileType jpg \ --sliceToConvert 20 @@ -287,7 +288,9 @@ resulting in :: - dicom-results/specific-slice/sample-slice020.jpg + dicom-results/specific-slice/sample.jpg + +Again, even though the first slice was supplied to the script, ``med2image`` selected and converted the 20th slice in the directory. Special Cases ^^^^^^^^^^^^^ From 20e53391c8423441b545dc4f00a6b91689239c5f Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:43:06 -0400 Subject: [PATCH 39/63] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f495172..647a795 100644 --- a/README.rst +++ b/README.rst @@ -223,7 +223,7 @@ Convert ``DICOM`` Convert all DICOMS in a directory/series ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -To convert all the ``DICOM``S in a directory, simply specify either ``--sliceToConvert -1`` (or just leave out the argument/value pair completely): +To convert all the ``DICOM`` files in a directory, simply specify either ``--sliceToConvert -1`` (or just leave out the argument/value pair completely): .. code:: bash From 3a994eea8f3f812b63d96f4ece3db192025861ba Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:47:30 -0400 Subject: [PATCH 40/63] Update README.rst --- README.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 647a795..1f42627 100644 --- a/README.rst +++ b/README.rst @@ -295,15 +295,15 @@ Again, even though the first slice was supplied to the script, ``med2image`` sel Special Cases ^^^^^^^^^^^^^ -For ``DICOM`` data, the can optionally be set to the value of an internal DICOM tag. The tag is specified by preceding the tag name with a percent character '%', so +For ``DICOM`` data, the ```` can optionally 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 %PatientID`` +- ``-o %PatientID`` -will use the ``DICOM`` ``PatientID`` to name the output file. Note that special characters (like spaces) in the DICOM value are replaced by underscores '_'. +will use the ``DICOM`` ``PatientID`` to name the output file. Note that special characters (like spaces) in the ``DICOM`` value are replaced by underscores '_'. .. code:: bash - med2image -i SAG-anon/slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/tags \ -o %PatientID.jpg -s m @@ -317,11 +317,11 @@ 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. +and the output filename will have each ``DICOM`` tag string as specified in order, connected with dashes. .. code:: bash - med2image -i SAG-anon/slice-name.dcm \ + med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/tags \ -o %PatientName%PatientID%ProtocolName.jpg \ -s m From 396c48a6950eaa1b6fbdc9e1105fc506b20cd6fa Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:48:52 -0400 Subject: [PATCH 41/63] Update README.rst --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 1f42627..e8b364a 100644 --- a/README.rst +++ b/README.rst @@ -315,7 +315,7 @@ This will create the following file in the ``tags`` sub-directory within ``dicom Multiple tags can be specified, for example - ``-o %PatientName%PatientID%ProtocolName`` +- ``-o %PatientName%PatientID%ProtocolName`` and the output filename will have each ``DICOM`` tag string as specified in order, connected with dashes. @@ -350,6 +350,7 @@ Special Operations ``med2image`` also supports some very basic image processing through a ``--func `` CLI, which applies some canned transformation on the image. Currently supported is :: + --func invertIntensities which simply inverts the contrast intensity of the source image. Additional functions are planned for future releases. From 97b12a0045d4cdb20c2129e6a6ab7577f7e9eb6b Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:51:08 -0400 Subject: [PATCH 42/63] Update README and bump to 2.2.2 --- README.rst | 9 ++++++++- bin/med2image | 2 +- setup.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index e8b364a..11c5b33 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.0 +med2image 2.2.2 ================== Quick Overview @@ -412,6 +412,13 @@ Command Line Arguments [--showSlices] If specified, render/show image slices as they are created. + [--func ] + Apply the specified transformation function before saving. Currently + support functions: + + * invertIntensities + Inverts the contrast intensity of the source image. + [--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 diff --git a/bin/med2image b/bin/med2image index 0658dbe..2cc7382 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.0" +str_version = "2.2.2" str_desc = Colors.CYAN + """ _ _____ _ diff --git a/setup.py b/setup.py index e6ed88d..62f1b94 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.0', + version = '2.2.2', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 599ae157b2b072796aa2983027b050bd154e285a Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:53:04 -0400 Subject: [PATCH 43/63] Minor README update and bump to 2.2.4 --- README.rst | 4 ++-- bin/med2image | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 11c5b33..82391b9 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.2 +med2image 2.2.4 ================== Quick Overview @@ -95,7 +95,7 @@ How to Use - ``med2image`` understands both types of inputs. Pull ``NIfTI`` -~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ The input should be a ``NIfTI`` volume with extension ``.nii``. We provide a sample volume here https://github.com/FNNDSC/SAG-anon-nii.git diff --git a/bin/med2image b/bin/med2image index 2cc7382..ab4b7d9 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.2" +str_version = "2.2.4" str_desc = Colors.CYAN + """ _ _____ _ diff --git a/setup.py b/setup.py index 62f1b94..3658400 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.2', + version = '2.2.4', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 7fbc8b95a00e293f36e3a6e3dae0b853f437be89 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 May 2020 10:53:56 -0400 Subject: [PATCH 44/63] RST check fix --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 82391b9..8e3c05c 100644 --- a/README.rst +++ b/README.rst @@ -106,7 +106,7 @@ The input should be a ``NIfTI`` volume with extension ``.nii``. We provide a sam git clone https://github.com/FNNDSC/SAG-anon-nii.git Convert ``NIfTI`` -~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~ **NOTE:** From 5ae2e8a3db0ddbb4d553a5d0b9b35c366ca815dc Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 29 Jun 2020 10:27:37 -0400 Subject: [PATCH 45/63] Update README.rst --- README.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 8e3c05c..4aafc8a 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,10 @@ This document assumes UNIX conventions and a ``bash`` shell. The script should w Installation ~~~~~~~~~~~~ -The best method of installing this script and all of its dependencies is by fetching it from `PyPI `_. +Python module +~~~~~~~~~~~~~ + +One method of installing this script and all of its dependencies is by fetching it from `PyPI `_. .. code:: bash @@ -47,6 +50,11 @@ Should you get an error about ``python3-tk`` not installed, simply do (for examp sudo apt-get update sudo apt-get install -y python3-tk +Docker container +~~~~~~~~~~~~~~~~ + +We also offer a docker container of ``med2image`` as a ChRIS-conformant platform plugin here https://github.com/FNNDSC/pl-med2img -- please consult that page for information on running the dockerized container. The containerized version exposes a similar CLI and functionality as this module. + How to Use ---------- From f5806447411c0caa32acdd8116679232d7f4e5da Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 23 Dec 2020 15:05:06 -0500 Subject: [PATCH 46/63] Add --convertOnlySingleDICOM flag and bump to 2.2.6 --- README.rst | 32 ++++++++++++++++++++------------ bin/med2image | 15 ++++++++++++++- setup.py | 2 +- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index 4aafc8a..d4f552e 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.4 +med2image 2.2.6 ================== Quick Overview @@ -68,27 +68,27 @@ How to Use .. code:: bash - # Convert a NifTI file 'vol.nii' to JPEG and store + # Convert a NifTI file 'vol.nii' to JPEG and store # the results in a dirctory called 'out'. - # The 'out' dir will contain a set of JPEG + # The 'out' dir will contain a set of JPEG # images of form 'output-sliceXXX.jpg'. med2image -i vol.nii -d out - + .. code:: bash - # Convert a DICOM file 'file.dcm' to JPEG and store + # Convert a DICOM file 'file.dcm' to JPEG and store # the results in a dirctory called 'out'. - # The 'out' dir will contain a set of JPEG + # The 'out' dir will contain a set of JPEG # images of form 'output-sliceXXX.jpg'. - + # NOTE! If the directory containing 'file.dcm' contains # multiple DICOM files, *ALL* of these will be converted # to JPEG. See later for only converting a *single* # DICOM file. - + med2image -i file.dcm -d out - + ``NIfTI`` details ----------------- @@ -226,6 +226,7 @@ Convert ``DICOM`` - If ``--outputDir | -d`` is not provided, any output(s) are created in the current directory. - if ``--sliceToConvert`` argument is not specified and if mutiple ``dcm`` files are contained in the input directory with the ``DICOM`` input, then all the ``.dcm`` files are converted. +- alternatively, specifying a ``--convertOnlySingleDICOM`` will only convert the DICOM file specified with the ``--inputFile`` flag. Convert all DICOMS in a directory/series @@ -246,7 +247,7 @@ To convert all the ``DICOM`` files in a directory, simply specify either ``--sli med2image -i SAG-anon/0001-1.3.12.2.1107.5.2.19.45152.2013030808110258929186035.dcm \ -d dicom-results/all-slices \ -o sample \ - --outputFileType jpg + --outputFileType jpg resulting in @@ -355,12 +356,12 @@ No interpolation in the ``x`` and ``y`` directions is performed. This often resu Special Operations ------------------ -``med2image`` also supports some very basic image processing through a ``--func `` CLI, which applies some canned transformation on the image. Currently supported is +``med2image`` also supports some very basic image processing through a ``--func `` CLI, which applies some canned transformation on the image. Currently supported is :: --func invertIntensities - + which simply inverts the contrast intensity of the source image. Additional functions are planned for future releases. Command Line Arguments @@ -401,6 +402,13 @@ Command Line Arguments and the output filename will have each DICOM tag string as specified in order, connected with dashes. + [--convertOnlySingleDICOM] + If specified, will only convert the single DICOM specified by the + '--inputFile' flag. This is useful for the case when an input + directory has many DICOMS but you specifially only want to convert + the named file. By default the script assumes that multiple DICOMS + should be converted en mass otherwise. + [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . diff --git a/bin/med2image b/bin/med2image index ab4b7d9..97bc131 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.4" +str_version = "2.2.6" str_desc = Colors.CYAN + """ _ _____ _ @@ -64,6 +64,7 @@ def synopsis(ab_shortOnly=False): -o|--output \\ [-t|--outputFileType ] \\ [-s|--sliceToConvert ] \\ + [--convertOnlySingleDICOM] \\ [-f|--frameToConvert ] \\ [--showSlices] \\ [--func ] \\ @@ -120,6 +121,13 @@ def synopsis(ab_shortOnly=False): and the output filename will have each DICOM tag string as specified in order, connected with dashes. + [--convertOnlySingleDICOM] + If specified, will only convert the single DICOM specified by the + '--inputFile' flag. This is useful for the case when an input + directory has many DICOMS but you specifially only want to convert + the named file. By default the script assumes that multiple DICOMS + should be converted en mass otherwise. + [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . @@ -223,6 +231,11 @@ parser.add_argument("-t", "--outputFileType", help = "output image type", dest = 'outputFileType', default = '') +parser.add_argument("--convertOnlySingleDICOM", + help = "if specified, only convert the specific input DICOM", + dest = 'convertOnlySingleDICOM', + action = 'store_true', + default = False) parser.add_argument("-s", "--sliceToConvert", help="slice to convert (for 3D data)", dest='sliceToConvert', diff --git a/setup.py b/setup.py index 3658400..c0fdb54 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.4', + version = '2.2.6', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 6c56038f91845b0c5bb00497629d0bdd1b950aa8 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 23 Dec 2020 15:05:23 -0500 Subject: [PATCH 47/63] Add logic for --convertOnlySingleDICOM --- med2image/med2image.py | 120 +++++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/med2image/med2image.py b/med2image/med2image.py index 77b1d5a..e86f2bd 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -90,41 +90,41 @@ class med2image(object): _dictErr = { 'inputFileFail' : { - 'action' : 'trying to read input file, ', - 'error' : 'could not access/read file -- does it exist? Do you have permission?', - 'exitCode' : 10}, + 'action' : 'trying to read input file, ', + 'error' : 'could not access/read file -- does it exist? Do you have permission?', + 'exitCode' : 10}, 'emailFail' : { - 'action' : 'attempting to send notification email, ', - 'error' : 'sending failed. Perhaps host is not email configured?', - 'exitCode' : 20}, + 'action' : 'attempting to send notification email, ', + 'error' : 'sending failed. Perhaps host is not email configured?', + 'exitCode' : 20}, 'dcmInsertionFail': { - 'action' : 'attempting insert DICOM into volume structure, ', - 'error' : 'a dimension mismatch occurred. This DICOM file is of different image size to the rest.', - 'exitCode' : 20}, + 'action' : 'attempting insert DICOM into volume structure, ', + 'error' : 'a dimension mismatch occurred. This DICOM file is of different image size to the rest.', + 'exitCode' : 30}, 'ProtocolNameTag': { - 'action' : 'attempting to parse DICOM header, ', - 'error' : 'the DICOM file does not seem to contain a ProtocolName tag.', - 'exitCode' : 30}, - 'PatientNameTag': { - 'action': 'attempting to parse DICOM header, ', - 'error': 'the DICOM file does not seem to contain a PatientName tag.', - 'exitCode': 30}, + 'action' : 'attempting to parse DICOM header, ', + 'error' : 'the DICOM file does not seem to contain a ProtocolName tag.', + 'exitCode' : 40}, + 'PatientNameTag': { + 'action': 'attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a PatientName tag.', + 'exitCode': 41}, 'PatientAgeTag': { - 'action': 'attempting to parse DICOM header, ', - 'error': 'the DICOM file does not seem to contain a PatientAge tag.', - 'exitCode': 30}, + 'action': ' attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a PatientAge tag.', + 'exitCode': 42}, 'PatientNameSex': { - 'action': 'attempting to parse DICOM header, ', - 'error': 'the DICOM file does not seem to contain a PatientSex tag.', - 'exitCode': 30}, + 'action': 'attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a PatientSex tag.', + 'exitCode': 43}, 'PatientIDTag': { - 'action': 'attempting to parse DICOM header, ', - 'error': 'the DICOM file does not seem to contain a PatientID tag.', - 'exitCode': 30}, + 'action': 'attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a PatientID tag.', + 'exitCode': 44}, 'SeriesDescriptionTag': { - 'action': 'attempting to parse DICOM header, ', - 'error': 'the DICOM file does not seem to contain a SeriesDescription tag.', - 'exitCode': 30} + 'action': 'attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a SeriesDescription tag.', + 'exitCode': 45} } @staticmethod @@ -221,6 +221,7 @@ def __init__(self, **kwargs): self._b_4D = False self._b_3D = False self._b_DICOM = False + self.convertOnlySingleDICOM = False self._Vnp_4DVol = None self._Vnp_3DVol = None self._Mnp_2Dslice = None @@ -247,16 +248,17 @@ def __init__(self, **kwargs): self.func = None #transformation function for key, value in kwargs.items(): - if key == "inputFile": self.str_inputFile = value - if key == "inputDir": self.str_inputDir = value - if key == "outputDir": self.str_outputDir = value - if key == "outputFileStem": self.str_outputFileStem = value - if key == "outputFileType": self.str_outputFileType = value - if key == "sliceToConvert": self.str_sliceToConvert = value - if key == "frameToConvert": self.str_frameToConvert = value - if key == "showSlices": self._b_showSlices = value - if key == 'reslice': self._b_reslice = value - if key == "func": self.func = value + if key == "inputFile": self.str_inputFile = value + if key == "inputDir": self.str_inputDir = value + if key == "outputDir": self.str_outputDir = value + if key == "outputFileStem": self.str_outputFileStem = value + if key == "outputFileType": self.str_outputFileType = value + if key == "sliceToConvert": self.str_sliceToConvert = value + if key == "frameToConvert": self.str_frameToConvert = value + if key == "convertOnlySingleDICOM": self.convertOnlySingleDICOM = value + if key == "showSlices": self._b_showSlices = value + if key == 'reslice': self._b_reslice = value + if key == "func": self.func = value if self.str_frameToConvert.lower() == 'm': self._b_convertMiddleFrame = True @@ -463,19 +465,18 @@ def __init__(self, **kwargs): self.l_dcmFileNames = sorted(glob.glob('%s/*.dcm' % self.str_inputDir)) self.slices = len(self.l_dcmFileNames) - if self._b_convertMiddleSlice: self._sliceToConvert = int(self.slices/2) self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] - - # if not self.str_outputFileStem.startswith('%'): - # self.str_outputFileStem, ext = os.path.splitext(self.l_dcmFileNames[self._sliceToConvert]) if not self._b_convertMiddleSlice and self._sliceToConvert != -1: self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] else: self._dcm = dicom.read_file(self.str_inputFile,force=True) + if self.convertOnlySingleDICOM: + self._sliceToConvert = 1 + self._dcm = dicom.read_file(self.str_inputFile,force=True) if self._sliceToConvert == -1: self._b_3D = True self._dcm = dicom.read_file(self.str_inputFile,force=True) @@ -494,7 +495,7 @@ def __init__(self, **kwargs): except Exception as e: self.warn( 'dcmInsertionFail', - '\nFor input DICOM file %s%s' % (img, str(e)), + '\nFor input DICOM file %s, %s' % (img, str(e)), True) i += 1 if self.str_outputFileStem.startswith('%'): @@ -711,26 +712,27 @@ def __init__(self, args): b_dicomExt = str_inputFileExtension == '.dcm' if b_niftiExt: self.C_convert = med2image_nii( - inputFile = args.inputFile, - inputDir = args.inputDir, - outputDir = args.outputDir, - outputFileStem = args.outputFileStem, - outputFileType = args.outputFileType, - sliceToConvert = args.sliceToConvert, - frameToConvert = args.frameToConvert, - showSlices = args.showSlices, - reslice = args.reslice + inputFile = args.inputFile, + inputDir = args.inputDir, + outputDir = args.outputDir, + outputFileStem = args.outputFileStem, + outputFileType = args.outputFileType, + sliceToConvert = args.sliceToConvert, + frameToConvert = args.frameToConvert, + showSlices = args.showSlices, + reslice = args.reslice ) print('sliceToConvert:', args.sliceToConvert) if b_dicomExt: self.C_convert = med2image_dcm( - inputFile = args.inputFile, - inputDir = args.inputDir, - outputDir = args.outputDir, - outputFileStem = args.outputFileStem, - outputFileType = args.outputFileType, - sliceToConvert = args.sliceToConvert, - reslice = args.reslice + inputFile = args.inputFile, + inputDir = args.inputDir, + outputDir = args.outputDir, + outputFileStem = args.outputFileStem, + outputFileType = args.outputFileType, + sliceToConvert = args.sliceToConvert, + convertOnlySingleDICOM = args.convertOnlySingleDICOM, + reslice = args.reslice ) From a4ab737f7204b80c60b3d795c42b860a9f8eca81 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 24 Dec 2020 12:17:01 -0500 Subject: [PATCH 48/63] Docs and handling for --inputFileSubStr and bump to 2.2.8 --- README.rst | 23 ++++++++++++++++++++--- bin/med2image | 26 ++++++++++++++++++++++---- setup.py | 2 +- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index d4f552e..b46aeb9 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.6 +med2image 2.2.8 ================== Quick Overview @@ -58,10 +58,12 @@ We also offer a docker container of ``med2image`` as a ChRIS-conformant platform How to Use ---------- -``med2image`` needs at a minimum the following required command line arguments: +``med2image`` needs at a minimum (some of) the following required command line arguments: - ``-i | --inputFile `` : Input file to convert. Typically a ``DICOM`` file or a ``NifTI`` volume. +- ``--inputFileSubStr `` : A short hand trick to specify the ``inputFile``. By only specifying a sub string that identifies the file, the first file in the ``inputDir`` that contains the sub string is tagged as the ``inputFile``. This saves a user from needing to specify long and cumbersome file names, esp in the case of many DICOM filenames. + - ``-d | --outputDir :`` The directory to contain the converted output image files. **Example:** @@ -119,6 +121,7 @@ Convert ``NIfTI`` **NOTE:** - If ``--outputDir | -d`` is not provided, outputs are created in the *current* directory. + - if ``--sliceToConvert`` is not provided, *all* the slices of the ``.nii`` volume are converted. Both 3D and 4D ``NIfTI`` input data are understood. In the case of 4D ``NIfTI``, a specific frame (``--frameToConvert``) can be additionally provided in conjunction with a specific slice index. Conversion options include: @@ -369,9 +372,23 @@ Command Line Arguments :: - -i|--inputFile + [-i|--inputFile ] Input file to convert. Typically a DICOM file or a nifti volume. + [--inputFileSubStr ] + As a convenience, the input file can be determined via a substring + search of all the files in the using this flag. The first + filename hit that contains the will be assigned the + . + + This flag is useful is input names are long and cumbersome, but + a short substring search would identify the file. For example, an + input file of + + 0043-1.3.12.2.1107.5.2.19.45152.2013030808110149471485951.dcm + + can be specified using ``--inputFileSubStr 0043-`` + [-I|--inputDir ] If specified, a directory containing the . In this case should be specified as relative to . diff --git a/bin/med2image b/bin/med2image index 97bc131..5c78fdb 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.6" +str_version = "2.2.8" str_desc = Colors.CYAN + """ _ _____ _ @@ -88,9 +88,23 @@ def synopsis(ab_shortOnly=False): ARGS - -i|--inputFile + [-i|--inputFile ] Input file to convert. Typically a DICOM file or a nifti volume. + [--inputFileSubStr ] + As a convenience, the input file can be determined via a substring + search of all the files in the using this flag. The first + filename hit that contains the will be assigned the + . + + This flag is useful is input names are long and cumbersome, but + a short substring search would identify the file. For example, an + input file of + + 0043-1.3.12.2.1107.5.2.19.45152.2013030808110149471485951.dcm + + can be specified using ``--inputFileSubStr 0043-`` + [-I|--inputDir ] If specified, a directory containing the . In this case should be specified as relative to . @@ -214,7 +228,12 @@ parser = ArgumentParser(description = str_desc, formatter_class = RawTextHelpFo parser.add_argument("-i", "--inputFile", help = "input file", - dest = 'inputFile') + dest = 'inputFile', + default = '') +parser.add_argument("--inputFileSubStr", + help = "input file substring", + dest = 'inputFileSubStr', + default = '') parser.add_argument("-I", "--inputDir", help = "input directory", dest = 'inputDir', @@ -297,7 +316,6 @@ if args.man or args.synopsis: print(str_help) sys.exit(1) -# sys.exit(0) # pudb.set_trace() # Create the object imgConverter = med2image.object_factoryCreate(args).C_convert diff --git a/setup.py b/setup.py index c0fdb54..af3f4f0 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.6', + version = '2.2.8', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 36b36e2be854bb6818ae5841917fed06dd4e51ad Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 24 Dec 2020 12:17:31 -0500 Subject: [PATCH 49/63] Add handling of inputFileSubStr and fix double dot extension bug --- med2image/med2image.py | 83 ++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/med2image/med2image.py b/med2image/med2image.py index e86f2bd..8b17eac 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -2,6 +2,10 @@ # System imports import os +from os import listdir +from os import walk +from os.path import isfile, join + import sys import glob import numpy as np @@ -10,11 +14,10 @@ import pudb # System dependency imports -import nibabel as nib -import pydicom as dicom -import pylab -import matplotlib.cm as cm - +import nibabel as nib +import pydicom as dicom +import pylab +import matplotlib.cm as cm import pfmisc from pfmisc._colors import Colors @@ -28,8 +31,10 @@ def report( callingClass, ): ''' Error handling. + Based on the , error information is extracted from _dictErr and sent to log object. + If is False, error is considered non-fatal and processing can continue, otherwise processing terminates. ''' @@ -193,27 +198,28 @@ def __init__(self, **kwargs): # # Object desc block # - self.str_desc = '' - # self._log = msg.Message() - # self._log._b_syslog = True - self.__name__ = "med2image" + self.str_desc = '' + # self._log = msg.Message() + # self._log._b_syslog = True + self.__name__ = "med2image" # Directory and filenames - self.str_workingDir = '' - self.str_inputFile = '' - self.str_outputFileStem = '' - self.str_outputFileType = '' - self.str_outputDir = '' - self.str_inputDir = '' + self.str_workingDir = '' + self.str_inputFile = '' + self.str_inputFileSubStr = '' + self.str_outputFileStem = '' + self.str_outputFileType = '' + self.str_outputDir = '' + self.str_inputDir = '' self._b_convertAllSlices = False - self.str_sliceToConvert = '' - self.str_frameToConvert = '' + self.str_sliceToConvert = '' + self.str_frameToConvert = '' self._sliceToConvert = -1 self._frameToConvert = -1 - self.str_stdout = "" - self.str_stderr = "" + self.str_stdout = "" + self.str_stderr = "" self._exitCode = 0 # The actual data volume and slice @@ -231,15 +237,11 @@ def __init__(self, **kwargs): self.verbosity = 1 # A logger - # self._log = msg.Message() - # self._log.syslog(True) - self.dp = pfmisc.debug( verbosity = self.verbosity, within = self.__name__ ) - # Flags self._b_showSlices = False self._b_convertMiddleSlice = False @@ -249,6 +251,7 @@ def __init__(self, **kwargs): for key, value in kwargs.items(): if key == "inputFile": self.str_inputFile = value + if key == "inputFileSubStr": self.str_inputFileSubStr = value if key == "inputDir": self.str_inputDir = value if key == "outputDir": self.str_outputDir = value if key == "outputFileStem": self.str_outputFileStem = value @@ -283,7 +286,7 @@ def __init__(self, **kwargs): self.str_outputFileType = str_fileExtension if not len(self.str_outputFileType) and not len(str_fileExtension): - self.str_outputFileType = '.png' + self.str_outputFileType = 'png' def tic(self): """ @@ -430,6 +433,7 @@ def slice_save(self, astr_outputFile): o astr_output The output filename to save the slice to. ''' + self.dp.qprint('Input file = %s' % self.str_inputFile) self.dp.qprint('Outputfile = %s' % astr_outputFile) fformat = astr_outputFile.split('.')[-1] if fformat == 'dcm': @@ -693,6 +697,37 @@ def __init__(self, args): """ Parse relevant CLI args. """ + + def inputFile_defineFromSubStr(astr_dir): + """ + This nested function simply determines the first + file in the that has a substring in the + filename that conforms to the . + + That file becomes the . The + is a useful shortcut for quickly identifying and using + a file without needing to provide its full name. + """ + l_filesInDir : list = [] + l_fileHit : list = [] + # First, get a list of all the files in the directory + (_, _, l_filesInDir) = next(os.walk(astr_dir)) + l_fileHit = [ + s for s in l_filesInDir if args.inputFileSubStr in s + ] + if len(l_fileHit): + return l_fileHit[0] + else: + return '' + + if len(args.inputFileSubStr): + args.inputFile = inputFile_defineFromSubStr(args.inputDir) + if not len(args.inputFile): + print( 'Input dir has no files with substring %s' % + args.inputFileSubStr) + print('Exiting to system with code 1.') + sys.exit(1) + str_outputFileStem, str_outputFileExtension = os.path.splitext(args.outputFileStem) if len(str_outputFileExtension): str_outputFileExtension = str_outputFileExtension.split('.')[1] From c4aee7280c69b87f505adee4f9291e234772e662 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 24 Dec 2020 12:19:53 -0500 Subject: [PATCH 50/63] Add CLI doc for inputFileSubStr and bump to 2.2.10 --- README.rst | 2 +- bin/med2image | 5 +++-- setup.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index b46aeb9..2651395 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.8 +med2image 2.2.10 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index 5c78fdb..78c3ec9 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.8" +str_version = "2.2.10" str_desc = Colors.CYAN + """ _ _____ _ @@ -58,7 +58,8 @@ def synopsis(ab_shortOnly=False): SYNOPSIS %s \\ - -i|--input \\ + [-i|--input ] \\ + [--inputFileSubStr ] \\ [-I|--inputDir ] \\ [-d|--outputDir ] \\ -o|--output \\ diff --git a/setup.py b/setup.py index af3f4f0..31e3f52 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.8', + version = '2.2.10', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From a07b5f1b15266ad9c6b5c39534e02f9f44447833 Mon Sep 17 00:00:00 2001 From: smasuda Date: Thu, 30 Sep 2021 08:49:03 +0900 Subject: [PATCH 51/63] fix warning message when PatientSexTag is missed --- med2image/med2image.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/med2image/med2image.py b/med2image/med2image.py index 8b17eac..f3c958c 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -129,7 +129,11 @@ class med2image(object): 'SeriesDescriptionTag': { 'action': 'attempting to parse DICOM header, ', 'error': 'the DICOM file does not seem to contain a SeriesDescription tag.', - 'exitCode': 45} + 'exitCode': 45}, + 'PatientSexTag': { + 'action': 'attempting to parse DICOM header, ', + 'error': 'the DICOM file does not seem to contain a PatientSex tag.', + 'exitCode': 46} } @staticmethod From 8dd9d98ca8c99df05931b326380e245cbf13dffe Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 10:17:30 -0400 Subject: [PATCH 52/63] Add/improve verbosity flag, add rotation angle and vector, bump to 2.4.0 --- bin/med2image | 44 ++++++++++++++----- med2image/med2image.py | 95 ++++++++++++++++++++++++++++-------------- setup.py | 2 +- 3 files changed, 98 insertions(+), 43 deletions(-) diff --git a/bin/med2image b/bin/med2image index 78c3ec9..8b67447 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.2.10" +str_version = "2.4.0" str_desc = Colors.CYAN + """ _ _____ _ @@ -71,7 +71,8 @@ def synopsis(ab_shortOnly=False): [--func ] \\ [--reslice] \\ [-x|--man] \\ - [-y|--synopsis] + [-y|--synopsis] \\ + [--verbosity ] BRIEF EXAMPLE @@ -162,6 +163,12 @@ def synopsis(ab_shortOnly=False): [--showSlices] If specified, render/show image slices as they are created. + [--rot <3DbinVector>] + A per dimension 90 degree rotation vector. Useful to rotate individual + dimensions. Default is '110', i.e. rotate 'x' and 'y' but not 'z'. Note that + for a non-reslice selection, only the 'z' (or third) element of the vector + is used. + [--func ] Apply the specified transformation function before saving. Currently support functions: @@ -181,6 +188,9 @@ def synopsis(ab_shortOnly=False): [-y|--synopsis] Show brief help. + [--verbosity ] + Control how chatty med2image is. Set to '0' for blissful silence. + EXAMPLES NIfTI @@ -283,6 +293,18 @@ parser.add_argument('--func', help = "apply transformation function before saving", dest = 'func', default = "") +parser.add_argument('--verbosity', + help = "apply transformation function before saving", + dest = 'verbosity', + default = "1") +parser.add_argument('--rot', + help = "3D slice/dimenstion rotation vector", + dest = 'rot', + default = "110") +parser.add_argument('--rotAngle', + help = "3D slice/dimenstion rotation angle", + dest = 'rotAngle', + default = "90") parser.add_argument("-x", "--man", help = "man", dest = 'man', @@ -317,16 +339,18 @@ if args.man or args.synopsis: print(str_help) sys.exit(1) -# pudb.set_trace() # Create the object imgConverter = med2image.object_factoryCreate(args).C_convert -# Set possible function handling -if args.func: imgConverter.func = args.func +if imgConverter: + # Set possible function handling + if args.func: imgConverter.func = args.func -# And now run it! -imgConverter.tic() -imgConverter.run() -if args.printElapsedTime: print("Elapsed time = %f seconds" % imgConverter.toc()) -sys.exit(0) + # And now run it! + imgConverter.tic() + imgConverter.run() + if args.printElapsedTime: print("Elapsed time = %f seconds" % imgConverter.toc()) + sys.exit(0) +else: + sys.exit(1) diff --git a/med2image/med2image.py b/med2image/med2image.py index f3c958c..e846c1f 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -12,7 +12,7 @@ import re import time import pudb - +from scipy import ndimage # System dependency imports import nibabel as nib import pydicom as dicom @@ -240,18 +240,14 @@ def __init__(self, **kwargs): self.verbosity = 1 - # A logger - self.dp = pfmisc.debug( - verbosity = self.verbosity, - within = self.__name__ - ) - # Flags self._b_showSlices = False self._b_convertMiddleSlice = False self._b_convertMiddleFrame = False self._b_reslice = False - self.func = None #transformation function + self.func = None # transformation function + self.rot = '110' + self.rotAngle = 90 for key, value in kwargs.items(): if key == "inputFile": self.str_inputFile = value @@ -266,6 +262,15 @@ def __init__(self, **kwargs): if key == "showSlices": self._b_showSlices = value if key == 'reslice': self._b_reslice = value if key == "func": self.func = value + if key == "verbosity": self.verbosity = int(value) + if key == "rot": self.rot = value + if key == "rotAngle": self.rotAngle = int(value) + + # A logger + self.dp = pfmisc.debug( + verbosity = self.verbosity, + within = self.__name__ + ) if self.str_frameToConvert.lower() == 'm': self._b_convertMiddleFrame = True @@ -382,7 +387,6 @@ def get_output_file_name(self, **kwargs): def dim_save(self, **kwargs): dims = self._Vnp_3DVol.shape - self.dp.qprint('Image volume logical (i, j, k) size: %s' % str(dims)) str_dim = 'z' b_makeSubDir = False b_rot90 = False @@ -406,6 +410,7 @@ def dim_save(self, **kwargs): if indexStart == 0 and indexStop == -1: indexStop = dims[dim_ix[str_dim]] + self.dp.qprint('Saving along "%s" dimension with %i degree rotation...' % (str_dim, self.rotAngle*b_rot90)) for i in range(indexStart, indexStop): if str_dim == 'x': self._Mnp_2Dslice = self._Vnp_3DVol[i, :, :] @@ -418,13 +423,14 @@ def dim_save(self, **kwargs): if str_outputFile.endswith('dcm'): self._dcm = self._dcmList[i] self.slice_save(str_outputFile) + self.dp.qprint('%d images saved along "%s" dimension.' % ((i+1), str_dim)) - def process_slice(self, b_rot90=None): + def process_slice(self, b_rot90 = False): ''' Processes a single slice. ''' if b_rot90: - self._Mnp_2Dslice = np.rot90(self._Mnp_2Dslice) + self._Mnp_2Dslice = ndimage.rotate(self._Mnp_2Dslice, self.rotAngle) if self.func == 'invertIntensities': self.invert_slice_intensities() @@ -437,8 +443,8 @@ def slice_save(self, astr_outputFile): o astr_output The output filename to save the slice to. ''' - self.dp.qprint('Input file = %s' % self.str_inputFile) - self.dp.qprint('Outputfile = %s' % astr_outputFile) + self.dp.qprint('Input file = %s' % self.str_inputFile, level = 3) + self.dp.qprint('Outputfile = %s' % astr_outputFile, level = 3) fformat = astr_outputFile.split('.')[-1] if fformat == 'dcm': if self._dcm: @@ -601,7 +607,9 @@ def run(self): if self._b_convertMiddleSlice: self.dp.qprint('Converting middle slice in DICOM series: %d' % self._sliceToConvert) - l_rot90 = [ True, True, False ] + dims = self._Vnp_3DVol.shape + self.dp.qprint('Image volume logical (i, j, k) size: %s' % str(dims)) + l_rot90 = [ bool(int(self.rot[0])), bool(int(self.rot[1])), bool(int(self.rot[2])) ] med2image.mkdir(self.str_outputDir) if not self._b_3D: str_outputFile = '%s/%s.%s' % (self.str_outputDir, @@ -613,10 +621,22 @@ def run(self): rotCount = 0 if self._b_reslice: for dim in ['x', 'y', 'z']: - self.dim_save(dimension = dim, makeSubDir = True, rot90 = l_rot90[rotCount], indexStart = 0, indexStop = -1) + self.dim_save( + dimension = dim, + makeSubDir = True, + rot90 = l_rot90[rotCount], + indexStart = 0, + indexStop = -1 + ) rotCount += 1 else: - self.dim_save(dimension = 'z', makeSubDir = False, rot90 = False, indexStart = 0, indexStop = -1) + self.dim_save( + dimension = 'z', + makeSubDir = False, + rot90 = l_rot90[2], + indexStart = 0, + indexStop = -1 + ) class med2image_nii(med2image): @@ -694,7 +714,9 @@ def run(self): class object_factoryCreate: """ A class that examines input file string for extension information and - returns the relevant convert object. + creates a relevant convert object (or None). + + Returns true or false denoting converter object creation. """ def __init__(self, args): @@ -715,7 +737,10 @@ def inputFile_defineFromSubStr(astr_dir): l_filesInDir : list = [] l_fileHit : list = [] # First, get a list of all the files in the directory - (_, _, l_filesInDir) = next(os.walk(astr_dir)) + try: + (_, _, l_filesInDir) = next(os.walk(astr_dir)) + except: + return '' l_fileHit = [ s for s in l_filesInDir if args.inputFileSubStr in s ] @@ -727,10 +752,10 @@ def inputFile_defineFromSubStr(astr_dir): if len(args.inputFileSubStr): args.inputFile = inputFile_defineFromSubStr(args.inputDir) if not len(args.inputFile): - print( 'Input dir has no files with substring %s' % - args.inputFileSubStr) - print('Exiting to system with code 1.') - sys.exit(1) + print( 'Input dir "%s" has no files with substring "%s"' % + (args.inputDir, args.inputFileSubStr)) + # print('Exiting to system with code 1.') + # sys.exit(1) str_outputFileStem, str_outputFileExtension = os.path.splitext(args.outputFileStem) if len(str_outputFileExtension): @@ -749,17 +774,20 @@ def inputFile_defineFromSubStr(astr_dir): b_niftiExt = (str_inputFileExtension == '.nii' or str_inputFileExtension == '.gz') b_dicomExt = str_inputFileExtension == '.dcm' + + self.C_convert = None if b_niftiExt: self.C_convert = med2image_nii( - inputFile = args.inputFile, - inputDir = args.inputDir, - outputDir = args.outputDir, - outputFileStem = args.outputFileStem, - outputFileType = args.outputFileType, - sliceToConvert = args.sliceToConvert, - frameToConvert = args.frameToConvert, - showSlices = args.showSlices, - reslice = args.reslice + inputFile = args.inputFile, + inputDir = args.inputDir, + outputDir = args.outputDir, + outputFileStem = args.outputFileStem, + outputFileType = args.outputFileType, + sliceToConvert = args.sliceToConvert, + frameToConvert = args.frameToConvert, + showSlices = args.showSlices, + reslice = args.reslice, + verbosity = args.verbosity ) print('sliceToConvert:', args.sliceToConvert) @@ -773,5 +801,8 @@ def inputFile_defineFromSubStr(astr_dir): outputFileType = args.outputFileType, sliceToConvert = args.sliceToConvert, convertOnlySingleDICOM = args.convertOnlySingleDICOM, - reslice = args.reslice + reslice = args.reslice, + rot = args.rot, + rotAngle = args.rotAngle, + verbosity = args.verbosity ) diff --git a/setup.py b/setup.py index 31e3f52..eac7902 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.2.10', + version = '2.4.0', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 99bcef4747f02984fd5fe9bcac7c7a9c423a1b58 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 10:54:55 -0400 Subject: [PATCH 53/63] Add internal doc for new flags and bump to 2.4.2 --- README.rst | 23 +++++++++++++++++++---- bin/med2image | 38 +++++++++++++++++++++++--------------- setup.py | 2 +- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/README.rst b/README.rst index 2651395..f06987e 100644 --- a/README.rst +++ b/README.rst @@ -445,6 +445,17 @@ Command Line Arguments [--showSlices] If specified, render/show image slices as they are created. + [--rot <3DbinVector>] + A per dimension binary rotation vector. Useful to rotate individual + dimensions by an angle specified with [--rotAngle ]. Default + is '110', i.e. rotate 'x' and 'y' but not 'z'. Note that for a + non-reslice selection, only the 'z' (or third) element of the vector + is used. + + [--rotAngle ] + Default 90 -- the rotation angle to apply to a given dimension of the + <3DbinVector> + [--func ] Apply the specified transformation function before saving. Currently support functions: @@ -453,13 +464,17 @@ Command Line Arguments Inverts the contrast intensity of the source image. [--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 is subdivided into - 'slice' (k), 'row' (i), and 'col' (j) subdirectories. + For 3D data only. Assuming [x,y,z] coordinates, the default is to save + along the 'z' direction. By passing a --reslice image data in the 'x' + and 'y' directions are also saved. Furthermore, the is + subdivided into 'slice' (z), 'row' (x), and 'col' (y) subdirectories. [-x|--man] Show full help. [-y|--synopsis] Show brief help. + + [--verbosity ] + Control how chatty med2image is. Set to '0' for blissful silence, '1' + for sane progress and '3' for full information. diff --git a/bin/med2image b/bin/med2image index 8b67447..34ecb40 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.4.0" +str_version = "2.4.2" str_desc = Colors.CYAN + """ _ _____ _ @@ -53,7 +53,7 @@ def synopsis(ab_shortOnly=False): shortSynopsis = ''' NAME - med2image.py - convert medical images to jpg/png/etc. + med2image.py - convert medical images to jpg/png/etc. SYNOPSIS @@ -70,13 +70,15 @@ def synopsis(ab_shortOnly=False): [--showSlices] \\ [--func ] \\ [--reslice] \\ + [--rotAngle ] \\ + [--rot <3vec>] \\ [-x|--man] \\ [-y|--synopsis] \\ [--verbosity ] BRIEF EXAMPLE - med2image.py -i slice.dcm -o slice.jpg + med2image.py -i slice.dcm -o slice.jpg ''' % scriptName @@ -164,11 +166,16 @@ def synopsis(ab_shortOnly=False): If specified, render/show image slices as they are created. [--rot <3DbinVector>] - A per dimension 90 degree rotation vector. Useful to rotate individual - dimensions. Default is '110', i.e. rotate 'x' and 'y' but not 'z'. Note that - for a non-reslice selection, only the 'z' (or third) element of the vector + A per dimension binary rotation vector. Useful to rotate individual + dimensions by an angle specified with [--rotAngle ]. Default + is '110', i.e. rotate 'x' and 'y' but not 'z'. Note that for a + non-reslice selection, only the 'z' (or third) element of the vector is used. + [--rotAngle ] + Default 90 -- the rotation angle to apply to a given dimension of the + <3DbinVector> + [--func ] Apply the specified transformation function before saving. Currently support functions: @@ -177,10 +184,10 @@ def synopsis(ab_shortOnly=False): Inverts the contrast intensity of the source image. [--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 is subdivided into - 'slice' (k), 'row' (i), and 'col' (j) subdirectories. + For 3D data only. Assuming [x,y,z] coordinates, the default is to save + along the 'z' direction. By passing a --reslice image data in the 'x' + and 'y' directions are also saved. Furthermore, the is + subdivided into 'slice' (z), 'row' (x), and 'col' (y) subdirectories. [-x|--man] Show full help. @@ -189,7 +196,8 @@ def synopsis(ab_shortOnly=False): Show brief help. [--verbosity ] - Control how chatty med2image is. Set to '0' for blissful silence. + Control how chatty med2image is. Set to '0' for blissful silence, '1' + for sane progress and '3' for full information. EXAMPLES @@ -198,22 +206,22 @@ def synopsis(ab_shortOnly=False): o Convert each slice in a NIfTI volume 'vol.nii' to a jpg called 'image-sliceXXX.jpg' and store results in a directory called 'out': - med2image -i vol.nii -d out -o image.jpg -s -1 + med2image -i vol.nii -d out -o image.jpg -s -1 o Convert only the middle slice in an input volume and store in current directory: - med2image -i vol.nii -o image.jpg -s m + med2image -i vol.nii -o image.jpg -s m o Convert a specific slice, i.e. slice 20 - med2image -i vol.nii -o image.jpg -s 20 + med2image -i vol.nii -o image.jpg -s 20 DICOM o Simply convert a DICOM file called 'slice.dcm' to a jpg called 'slice.jpg': - med2image -i slice.dcm -o slice.jpg + med2image -i slice.dcm -o slice.jpg o Convert all DICOMs in a directory. Note that is assumes all DICOM files in the directory containing the passed file belong to the same series. diff --git a/setup.py b/setup.py index eac7902..27a18ed 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.0', + version = '2.4.2', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 4f14943a1c15e9e55efe31a89920a2905e7f2e99 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 11:03:36 -0400 Subject: [PATCH 54/63] Fix in-line help for flag --- bin/med2image | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/med2image b/bin/med2image index 34ecb40..e1afffc 100755 --- a/bin/med2image +++ b/bin/med2image @@ -302,7 +302,7 @@ parser.add_argument('--func', dest = 'func', default = "") parser.add_argument('--verbosity', - help = "apply transformation function before saving", + help = "verbosity level for app", dest = 'verbosity', default = "1") parser.add_argument('--rot', From ef4987697db5ae33fb6c0709d94a3c4b841730f7 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 11:04:05 -0400 Subject: [PATCH 55/63] v2.4.4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 27a18ed..fddce9f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.2', + version = '2.4.4', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 78f926a2b0cc95ca6ef8c8249ddde03f9e128b4f Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 13:32:31 -0400 Subject: [PATCH 56/63] Add args.func to constructor call and indicate function application (if valid) --- med2image/med2image.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/med2image/med2image.py b/med2image/med2image.py index e846c1f..c576f8b 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -423,7 +423,13 @@ def dim_save(self, **kwargs): if str_outputFile.endswith('dcm'): self._dcm = self._dcmList[i] self.slice_save(str_outputFile) - self.dp.qprint('%d images saved along "%s" dimension.' % ((i+1), str_dim)) + self.dp.qprint('%d images saved along "%s" dimension' % ((i+1), str_dim), + end = '') + if self.func: + self.dp.qprint(" with '%s' function applied." % self.func, + syslog = False) + else: + self.dp.qprint(".", syslog = False) def process_slice(self, b_rot90 = False): ''' @@ -786,6 +792,7 @@ def inputFile_defineFromSubStr(astr_dir): sliceToConvert = args.sliceToConvert, frameToConvert = args.frameToConvert, showSlices = args.showSlices, + func = args.func, reslice = args.reslice, verbosity = args.verbosity ) @@ -804,5 +811,6 @@ def inputFile_defineFromSubStr(astr_dir): reslice = args.reslice, rot = args.rot, rotAngle = args.rotAngle, + func = args.func, verbosity = args.verbosity ) From ae47150ce2feb0a106836abfa995d747de21c977 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Mon, 25 Apr 2022 18:02:05 -0400 Subject: [PATCH 57/63] Add .func to constructor and bump to 2.4.12 --- README.rst | 4 ++-- bin/med2image | 8 +++----- setup.py | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index f06987e..e2adca4 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.2.10 +med2image 2.4.12 ================== Quick Overview @@ -53,7 +53,7 @@ Should you get an error about ``python3-tk`` not installed, simply do (for examp Docker container ~~~~~~~~~~~~~~~~ -We also offer a docker container of ``med2image`` as a ChRIS-conformant platform plugin here https://github.com/FNNDSC/pl-med2img -- please consult that page for information on running the dockerized container. The containerized version exposes a similar CLI and functionality as this module. +We also offer a docker container of ``med2image`` as a ChRIS-conformant platform plugin here https://github.com/FNNDSC/pl-med2img (see also the closely related https://github.com/FNNDSC/pl-dcm2img that performs conversions down a directory tree recursively) -- please that reference for information on running the dockerized container. The containerized version exposes a similar CLI and functionality as this module. How to Use ---------- diff --git a/bin/med2image b/bin/med2image index e1afffc..ec226db 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.4.2" +str_version = "2.4.12" str_desc = Colors.CYAN + """ _ _____ _ @@ -350,11 +350,9 @@ if args.man or args.synopsis: # Create the object imgConverter = med2image.object_factoryCreate(args).C_convert +# and if it's valid... if imgConverter: - # Set possible function handling - if args.func: imgConverter.func = args.func - - # And now run it! + # run it! imgConverter.tic() imgConverter.run() if args.printElapsedTime: print("Elapsed time = %f seconds" % imgConverter.toc()) diff --git a/setup.py b/setup.py index fddce9f..c06341f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.4', + version = '2.4.12', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From fc0fc842d2cde8350d7afa1a5075a76ed18464b0 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Tue, 26 Apr 2022 14:38:47 -0400 Subject: [PATCH 58/63] replace os.mkdir with os.mkdirs and bump to 2.4.16 --- README.rst | 2 +- bin/med2image | 4 ++-- med2image/med2image.py | 4 ++-- setup.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index e2adca4..5fd70ce 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.4.12 +med2image 2.4.16 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index ec226db..bc5946b 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.4.12" +str_version = "2.4.16" str_desc = Colors.CYAN + """ _ _____ _ @@ -101,7 +101,7 @@ def synopsis(ab_shortOnly=False): filename hit that contains the will be assigned the . - This flag is useful is input names are long and cumbersome, but + This flag is useful if input names are long and cumbersome, but a short substring search would identify the file. For example, an input file of diff --git a/med2image/med2image.py b/med2image/med2image.py index c576f8b..6bb3fff 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -152,9 +152,9 @@ def mkdir(newdir, mode=0x775): else: head, tail = os.path.split(newdir) if head and not os.path.isdir(head): - os.mkdir(head) + os.mkdirs(head, exist_ok=True) if tail: - os.mkdir(newdir) + os.mkdirs(newdir, exist_ok=True) def log(self, *args): ''' diff --git a/setup.py b/setup.py index c06341f..f4cb339 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.12', + version = '2.4.16', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From cc458e062ca417b072f31b95a9039be13a6444aa Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 Apr 2022 09:56:04 -0400 Subject: [PATCH 59/63] Debug and WIP for preserveDICOMinputName --- README.rst | 2 +- bin/med2image | 12 +++++- med2image/med2image.py | 93 ++++++++++++++++++++++++------------------ setup.py | 2 +- 4 files changed, 66 insertions(+), 43 deletions(-) diff --git a/README.rst b/README.rst index 5fd70ce..fa0be37 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.4.16 +med2image 2.4.24 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index bc5946b..ddda334 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.4.16" +str_version = "2.4.24" str_desc = Colors.CYAN + """ _ _____ _ @@ -66,6 +66,7 @@ def synopsis(ab_shortOnly=False): [-t|--outputFileType ] \\ [-s|--sliceToConvert ] \\ [--convertOnlySingleDICOM] \\ + [--preserveDICOMinputName] \\ [-f|--frameToConvert ] \\ [--showSlices] \\ [--func ] \\ @@ -146,6 +147,10 @@ def synopsis(ab_shortOnly=False): the named file. By default the script assumes that multiple DICOMS should be converted en mass otherwise. + [--preserveDICOMinputName] + If specified, use the input DICOM name as the base of the output + filename. + [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . @@ -274,6 +279,11 @@ parser.add_argument("--convertOnlySingleDICOM", dest = 'convertOnlySingleDICOM', action = 'store_true', default = False) +parser.add_argument("--preserveDICOMinputName", + help = "if specified, save output files with the basename of their input DICOM", + dest = 'preserveDICOMinputName', + action = 'store_true', + default = False) parser.add_argument("-s", "--sliceToConvert", help="slice to convert (for 3D data)", dest='sliceToConvert', diff --git a/med2image/med2image.py b/med2image/med2image.py index 6bb3fff..3862f6e 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -5,6 +5,7 @@ from os import listdir from os import walk from os.path import isfile, join +from pathlib import Path import sys import glob @@ -150,11 +151,12 @@ def mkdir(newdir, mode=0x775): raise OSError("a file with the same name as the desired " \ "dir, '%s', already exists." % newdir) else: - head, tail = os.path.split(newdir) - if head and not os.path.isdir(head): - os.mkdirs(head, exist_ok=True) - if tail: - os.mkdirs(newdir, exist_ok=True) + Path(newdir).mkdir(parents = True, exist_ok = True) + # head, tail = os.path.split(newdir) + # if head and not os.path.isdir(head): + # os.mkdirs(head, exist_ok=True) + # if tail: + # os.mkdirs(newdir, exist_ok=True) def log(self, *args): ''' @@ -210,6 +212,7 @@ def __init__(self, **kwargs): # Directory and filenames self.str_workingDir = '' self.str_inputFile = '' + self.lstr_inputFile = [] self.str_inputFileSubStr = '' self.str_outputFileStem = '' self.str_outputFileType = '' @@ -232,6 +235,7 @@ def __init__(self, **kwargs): self._b_3D = False self._b_DICOM = False self.convertOnlySingleDICOM = False + self.preserveDICOMinputName = False self._Vnp_4DVol = None self._Vnp_3DVol = None self._Mnp_2Dslice = None @@ -259,6 +263,7 @@ def __init__(self, **kwargs): if key == "sliceToConvert": self.str_sliceToConvert = value if key == "frameToConvert": self.str_frameToConvert = value if key == "convertOnlySingleDICOM": self.convertOnlySingleDICOM = value + if key == "preserveDICOMinputName": self.preserveDICOMinputName = value if key == "showSlices": self._b_showSlices = value if key == 'reslice': self._b_reslice = value if key == "func": self.func = value @@ -377,11 +382,14 @@ def get_output_file_name(self, **kwargs): frame, index, self.str_outputFileType) else: - str_outputFile = '%s/%s/%s-slice%03d.%s' % ( + if self.preserveDICOMinputName: + str_filePart = self.lstr_inputFile[index] + else: + str_filePart = '%s-slice%03d' % (self.str_outputFileStem, index) + str_outputFile = '%s/%s/%s-slice%03d.%s' % ( self.str_outputDir, str_subDir, - self.str_outputFileStem, - index, + str_filePart, self.str_outputFileType) return str_outputFile @@ -442,12 +450,10 @@ def process_slice(self, b_rot90 = False): def slice_save(self, astr_outputFile): ''' - Saves a single slice. - ARGS o astr_output - The output filename to save the slice to. + The output filename. ''' self.dp.qprint('Input file = %s' % self.str_inputFile, level = 3) self.dp.qprint('Outputfile = %s' % astr_outputFile, level = 3) @@ -485,29 +491,32 @@ def __init__(self, **kwargs): self.l_dcmFileNames = sorted(glob.glob('%s/*.dcm' % self.str_inputDir)) self.slices = len(self.l_dcmFileNames) - if self._b_convertMiddleSlice: - self._sliceToConvert = int(self.slices/2) - self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) - self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] - if not self._b_convertMiddleSlice and self._sliceToConvert != -1: - self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) - self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] + if self._sliceToConvert != -1 or self.convertOnlySingleDICOM: + if self._b_convertMiddleSlice: + self._sliceToConvert = int(self.slices/2) + self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) + self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] + if not self._b_convertMiddleSlice and self._sliceToConvert != -1: + self._dcm = dicom.read_file(self.l_dcmFileNames[self._sliceToConvert],force=True) + self.str_inputFile = self.l_dcmFileNames[self._sliceToConvert] + else: + self._dcm = dicom.read_file(self.str_inputFile,force=True) + if self.convertOnlySingleDICOM: + self._sliceToConvert = 1 + self._dcm = dicom.read_file(self.str_inputFile,force=True) + self.lstr_inputFile.append(os.path.basename(self.str_inputFile)) else: - self._dcm = dicom.read_file(self.str_inputFile,force=True) - if self.convertOnlySingleDICOM: - self._sliceToConvert = 1 - self._dcm = dicom.read_file(self.str_inputFile,force=True) - if self._sliceToConvert == -1: - self._b_3D = True - self._dcm = dicom.read_file(self.str_inputFile,force=True) - image = self._dcm.pixel_array - shape2D = image.shape + self._b_3D = True + self._dcm = dicom.read_file(self.str_inputFile,force=True) + image = self._dcm.pixel_array + shape2D = image.shape #print(shape2D) - self._Vnp_3DVol = np.empty( (shape2D[0], shape2D[1], self.slices) ) - i = 0 + self._Vnp_3DVol = np.empty( (shape2D[0], shape2D[1], self.slices) ) + i = 0 for img in self.l_dcmFileNames: - self._dcm = dicom.read_file(img,force=True) - image = self._dcm.pixel_array + self._dcm = dicom.read_file(img,force=True) + self.lstr_inputFile.append(os.path.basename(self.str_inputFile)) + image = self._dcm.pixel_array self._dcmList.append(self._dcm) #print('%s: %s' % (img, image.shape)) try: @@ -519,17 +528,17 @@ def __init__(self, **kwargs): True) i += 1 if self.str_outputFileStem.startswith('%'): - str_spec = self.str_outputFileStem + str_spec = self.str_outputFileStem self.str_outputFileStem = '' for key in str_spec.split('%')[1:]: - str_fileComponent = '' + str_fileComponent = '' if key == 'inputFile': - str_fileName, str_ext = os.path.splitext(self.str_inputFile) - str_fileComponent = str_fileName + str_fileName, str_ext = os.path.splitext(self.str_inputFile) + str_fileComponent = str_fileName else: # pudb.set_trace() - str_fileComponent = eval('str(self._dcm.%s)' % key) - str_fileComponent = med2image.urlify(str_fileComponent) + str_fileComponent = eval('str(self._dcm.%s)' % key) + str_fileComponent = med2image.urlify(str_fileComponent) if not len(self.str_outputFileStem): self.str_outputFileStem = str_fileComponent else: @@ -613,17 +622,20 @@ def run(self): if self._b_convertMiddleSlice: self.dp.qprint('Converting middle slice in DICOM series: %d' % self._sliceToConvert) - dims = self._Vnp_3DVol.shape - self.dp.qprint('Image volume logical (i, j, k) size: %s' % str(dims)) l_rot90 = [ bool(int(self.rot[0])), bool(int(self.rot[1])), bool(int(self.rot[2])) ] med2image.mkdir(self.str_outputDir) if not self._b_3D: - str_outputFile = '%s/%s.%s' % (self.str_outputDir, + if self.preserveDICOMinputName: + str_outputFile = self.lstr_inputFile[0] + else: + str_outputFile = '%s/%s.%s' % (self.str_outputDir, self.str_outputFileStem, self.str_outputFileType) self.process_slice() self.slice_save(str_outputFile) if self._b_3D: + dims = self._Vnp_3DVol.shape + self.dp.qprint('Image volume logical (i, j, k) size: %s' % str(dims)) rotCount = 0 if self._b_reslice: for dim in ['x', 'y', 'z']: @@ -808,6 +820,7 @@ def inputFile_defineFromSubStr(astr_dir): outputFileType = args.outputFileType, sliceToConvert = args.sliceToConvert, convertOnlySingleDICOM = args.convertOnlySingleDICOM, + preserveDICOMinputName = args.preserveDICOMinputName, reslice = args.reslice, rot = args.rot, rotAngle = args.rotAngle, diff --git a/setup.py b/setup.py index f4cb339..fecb3dd 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.16', + version = '2.4.24', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 1bf9d410fcae4464f36d234312db9866837cdf56 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Wed, 27 Apr 2022 17:43:36 -0400 Subject: [PATCH 60/63] Release with tested --preserveDICOMinputName flag as well as --convertOnlySingleDICOM --- README.rst | 8 +++++++- bin/med2image | 8 +++++--- med2image/med2image.py | 13 +++++++------ setup.py | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index fa0be37..d4f5522 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.4.24 +med2image 2.6.0 ================== Quick Overview @@ -426,6 +426,12 @@ Command Line Arguments the named file. By default the script assumes that multiple DICOMS should be converted en mass otherwise. + [--preserveDICOMinputName] + If specified, use the input DICOM name as the stem of the output + filename, with the specified type ('jpg' or 'png') as the extension. + In the case where [--reslice] is additionally specified, only the + slice or 'z' direction will preserve original DICOM names. + [-t|--outputFileType ] The output file type. If different to extension, will override extension in favour of . diff --git a/bin/med2image b/bin/med2image index ddda334..6a1164e 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.4.24" +str_version = "2.6.0" str_desc = Colors.CYAN + """ _ _____ _ @@ -148,8 +148,10 @@ def synopsis(ab_shortOnly=False): should be converted en mass otherwise. [--preserveDICOMinputName] - If specified, use the input DICOM name as the base of the output - filename. + If specified, use the input DICOM name as the stem of the output + filename, with the specified type ('jpg' or 'png') as the extension. + In the case where [--reslice] is additionally specified, only the + slice or 'z' direction will preserve original DICOM names. [-t|--outputFileType ] The output file type. If different to extension, diff --git a/med2image/med2image.py b/med2image/med2image.py index 3862f6e..295424a 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -382,11 +382,11 @@ def get_output_file_name(self, **kwargs): frame, index, self.str_outputFileType) else: - if self.preserveDICOMinputName: - str_filePart = self.lstr_inputFile[index] + if self.preserveDICOMinputName and str_subDir == 'z' or str_subDir == '': + str_filePart = os.path.splitext(self.lstr_inputFile[index])[0] else: str_filePart = '%s-slice%03d' % (self.str_outputFileStem, index) - str_outputFile = '%s/%s/%s-slice%03d.%s' % ( + str_outputFile = '%s/%s/%s.%s' % ( self.str_outputDir, str_subDir, str_filePart, @@ -417,7 +417,6 @@ def dim_save(self, **kwargs): dim_ix = {'x':0, 'y':1, 'z':2} if indexStart == 0 and indexStop == -1: indexStop = dims[dim_ix[str_dim]] - self.dp.qprint('Saving along "%s" dimension with %i degree rotation...' % (str_dim, self.rotAngle*b_rot90)) for i in range(indexStart, indexStop): if str_dim == 'x': @@ -515,7 +514,7 @@ def __init__(self, **kwargs): i = 0 for img in self.l_dcmFileNames: self._dcm = dicom.read_file(img,force=True) - self.lstr_inputFile.append(os.path.basename(self.str_inputFile)) + self.lstr_inputFile.append(os.path.basename(img)) image = self._dcm.pixel_array self._dcmList.append(self._dcm) #print('%s: %s' % (img, image.shape)) @@ -626,7 +625,9 @@ def run(self): med2image.mkdir(self.str_outputDir) if not self._b_3D: if self.preserveDICOMinputName: - str_outputFile = self.lstr_inputFile[0] + str_outputFile = '%s/%s.%s' % (self.str_outputDir, + os.path.splitext(self.lstr_inputFile[0])[0], + self.str_outputFileType) else: str_outputFile = '%s/%s.%s' % (self.str_outputDir, self.str_outputFileStem, diff --git a/setup.py b/setup.py index fecb3dd..ebd0055 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.4.24', + version = '2.6.0', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From c66e5c7b9c0ff0c61383d1840501a7f3bf0a4508 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 28 Apr 2022 13:09:45 -0400 Subject: [PATCH 61/63] Improve stdout for single DICOM conversion --- README.rst | 2 +- bin/med2image | 2 +- med2image/med2image.py | 60 +++++++++++++++++++++--------------------- setup.py | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.rst b/README.rst index d4f5522..b895171 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.6.0 +med2image 2.6.2 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index 6a1164e..96314bb 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.6.0" +str_version = "2.6.2" str_desc = Colors.CYAN + """ _ _____ _ diff --git a/med2image/med2image.py b/med2image/med2image.py index 295424a..f0f236c 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -276,6 +276,7 @@ def __init__(self, **kwargs): verbosity = self.verbosity, within = self.__name__ ) + self.LOG = self.dp.qprint if self.str_frameToConvert.lower() == 'm': self._b_convertMiddleFrame = True @@ -417,7 +418,7 @@ def dim_save(self, **kwargs): dim_ix = {'x':0, 'y':1, 'z':2} if indexStart == 0 and indexStop == -1: indexStop = dims[dim_ix[str_dim]] - self.dp.qprint('Saving along "%s" dimension with %i degree rotation...' % (str_dim, self.rotAngle*b_rot90)) + self.LOG('Saving along "%s" dimension with %i degree rotation...' % (str_dim, self.rotAngle*b_rot90)) for i in range(indexStart, indexStop): if str_dim == 'x': self._Mnp_2Dslice = self._Vnp_3DVol[i, :, :] @@ -430,13 +431,13 @@ def dim_save(self, **kwargs): if str_outputFile.endswith('dcm'): self._dcm = self._dcmList[i] self.slice_save(str_outputFile) - self.dp.qprint('%d images saved along "%s" dimension' % ((i+1), str_dim), + self.LOG('%d images saved along "%s" dimension' % ((i+1), str_dim), end = '') if self.func: - self.dp.qprint(" with '%s' function applied." % self.func, + self.LOG(" with '%s' function applied." % self.func, syslog = False) else: - self.dp.qprint(".", syslog = False) + self.LOG(".", syslog = False) def process_slice(self, b_rot90 = False): ''' @@ -454,8 +455,8 @@ def slice_save(self, astr_outputFile): o astr_output The output filename. ''' - self.dp.qprint('Input file = %s' % self.str_inputFile, level = 3) - self.dp.qprint('Outputfile = %s' % astr_outputFile, level = 3) + self.LOG('Input file = %s' % self.str_inputFile, level = 3) + self.LOG('Outputfile = %s' % astr_outputFile, level = 3) fformat = astr_outputFile.split('.')[-1] if fformat == 'dcm': if self._dcm: @@ -568,17 +569,17 @@ def warn(self, str_tag, str_extraMsg = '', b_exit = False): str_action = med2image._dictErr[str_tag]['action'] str_error = med2image._dictErr[str_tag]['error'] exitCode = med2image._dictErr[str_tag]['exitCode'] - self.dp.qprint( + self.LOG( 'Some error seems to have occured!', comms = 'error' ) - self.dp.qprint( + self.LOG( 'While %s' % str_action, comms = 'error' ) - self.dp.qprint( + self.LOG( '%s' % str_error, comms = 'error' ) if len(str_extraMsg): - self.dp.qprint(str_extraMsg, comms = 'error') + self.LOG(str_extraMsg, comms = 'error') if b_exit: sys.exit(exitCode) @@ -586,41 +587,40 @@ def run(self): ''' Runs the DICOM conversion based on internal state. ''' - self.dp.qprint('Converting DICOM image.') + self.LOG('DICOM conversion (ref: %s).' % self.lstr_inputFile[0]) + if self._b_convertMiddleSlice: + self.LOG('Converting middle slice in DICOM series') try: - self.dp.qprint('PatientName: %s' % self._dcm.PatientName) + self.LOG('\tPatientName: %s' % self._dcm.PatientName) except AttributeError: - self.dp.qprint('PatientName: %s' % 'PatientName not found in DCM header.') + self.LOG('\tPatientName: %s' % 'PatientName not found in DCM header.') self.warn( 'PatientNameTag') try: - self.dp.qprint('PatientAge: %s' % self._dcm.PatientAge) + self.LOG('\tPatientAge: %s' % self._dcm.PatientAge) except AttributeError: - self.dp.qprint('PatientAge: %s' % 'PatientAge not found in DCM header.') + self.LOG('\tPatientAge: %s' % 'PatientAge not found in DCM header.') self.warn( 'PatientAgeTag') try: - self.dp.qprint('PatientSex: %s' % self._dcm.PatientSex) + self.LOG('\tPatientSex: %s' % self._dcm.PatientSex) except AttributeError: - self.dp.qprint('PatientSex: %s' % 'PatientSex not found in DCM header.') + self.LOG('\tPatientSex: %s' % 'PatientSex not found in DCM header.') self.warn( 'PatientSexTag') try: - self.dp.qprint('PatientID: %s' % self._dcm.PatientID) + self.LOG('\tPatientID: %s' % self._dcm.PatientID) except AttributeError: - self.dp.qprint('PatientID: %s' % 'PatientID not found in DCM header.') + self.LOG('\tPatientID: %s' % 'PatientID not found in DCM header.') self.warn( 'PatientIDTag') try: - self.dp.qprint('SeriesDescription: %s' % self._dcm.SeriesDescription) + self.LOG('\tSeriesDescription: %s' % self._dcm.SeriesDescription) except AttributeError: - self.dp.qprint('SeriesDescription: %s' % 'SeriesDescription not found in DCM header.') + self.LOG('\tSeriesDescription: %s' % 'SeriesDescription not found in DCM header.') self.warn( 'SeriesDescriptionTag') try: - self.dp.qprint('ProtocolName: %s' % self._dcm.ProtocolName) + self.LOG('\tProtocolName: %s' % self._dcm.ProtocolName) except AttributeError: - self.dp.qprint('ProtocolName: %s' % 'ProtocolName not found in DCM header.') + self.LOG('\tProtocolName: %s' % 'ProtocolName not found in DCM header.') self.warn( 'ProtocolNameTag') - if self._b_convertMiddleSlice: - self.dp.qprint('Converting middle slice in DICOM series: %d' % self._sliceToConvert) - l_rot90 = [ bool(int(self.rot[0])), bool(int(self.rot[1])), bool(int(self.rot[2])) ] med2image.mkdir(self.str_outputDir) if not self._b_3D: @@ -636,7 +636,7 @@ def run(self): self.slice_save(str_outputFile) if self._b_3D: dims = self._Vnp_3DVol.shape - self.dp.qprint('Image volume logical (i, j, k) size: %s' % str(dims)) + self.LOG('Image volume logical (i, j, k) size: %s' % str(dims)) rotCount = 0 if self._b_reslice: for dim in ['x', 'y', 'z']: @@ -685,7 +685,7 @@ def run(self): Runs the NIfTI conversion based on internal state. ''' - self.dp.qprint('About to perform NifTI to %s conversion...\n' % + self.LOG('About to perform NifTI to %s conversion...\n' % self.str_outputFileType) frames = 1 @@ -696,10 +696,10 @@ def run(self): sliceEnd = 0 if self._b_4D: - self.dp.qprint('4D volume detected.\n') + self.LOG('4D volume detected.\n') frames = self._Vnp_4DVol.shape[3] if self._b_3D: - self.dp.qprint('3D volume detected.\n') + self.LOG('3D volume detected.\n') if self._b_convertMiddleFrame: self._frameToConvert = int(frames/2) diff --git a/setup.py b/setup.py index ebd0055..4a9320e 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.6.0', + version = '2.6.2', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 656c79764af48b51d63e1e6089b307f8440a5f2f Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 28 Apr 2022 15:05:58 -0400 Subject: [PATCH 62/63] Fix minor typo in docs and bump to 2.6.4 --- README.rst | 2 +- bin/med2image | 4 ++-- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index b895171..ba7e657 100644 --- a/README.rst +++ b/README.rst @@ -460,7 +460,7 @@ Command Line Arguments [--rotAngle ] Default 90 -- the rotation angle to apply to a given dimension of the - <3DbinVector> + <3DbinVector>. [--func ] Apply the specified transformation function before saving. Currently diff --git a/bin/med2image b/bin/med2image index 96314bb..7a9a175 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.6.2" +str_version = "2.6.4" str_desc = Colors.CYAN + """ _ _____ _ @@ -181,7 +181,7 @@ def synopsis(ab_shortOnly=False): [--rotAngle ] Default 90 -- the rotation angle to apply to a given dimension of the - <3DbinVector> + <3DbinVector>. [--func ] Apply the specified transformation function before saving. Currently diff --git a/setup.py b/setup.py index 4a9320e..4659097 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.6.2', + version = '2.6.4', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC', From 2828c1c1a8c512ba5cf519182302d51e1be59d48 Mon Sep 17 00:00:00 2001 From: Rudolph Pienaar Date: Thu, 28 Apr 2022 15:47:51 -0400 Subject: [PATCH 63/63] Fix logic error on --preserveDICOMinputName and bump to 2.6.6 --- README.rst | 2 +- bin/med2image | 2 +- med2image/med2image.py | 2 +- setup.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index ba7e657..b19998d 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -med2image 2.6.2 +med2image 2.6.6 ================== Quick Overview diff --git a/bin/med2image b/bin/med2image index 7a9a175..7a50504 100755 --- a/bin/med2image +++ b/bin/med2image @@ -21,7 +21,7 @@ from pfmisc._colors import Colors import pudb -str_version = "2.6.4" +str_version = "2.6.6" str_desc = Colors.CYAN + """ _ _____ _ diff --git a/med2image/med2image.py b/med2image/med2image.py index f0f236c..9c3474d 100755 --- a/med2image/med2image.py +++ b/med2image/med2image.py @@ -383,7 +383,7 @@ def get_output_file_name(self, **kwargs): frame, index, self.str_outputFileType) else: - if self.preserveDICOMinputName and str_subDir == 'z' or str_subDir == '': + if self.preserveDICOMinputName and (str_subDir == 'z' or str_subDir == ''): str_filePart = os.path.splitext(self.lstr_inputFile[index])[0] else: str_filePart = '%s-slice%03d' % (self.str_outputFileStem, index) diff --git a/setup.py b/setup.py index 4659097..b2e6f34 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ def readme(): setup( name = 'med2image', - version = '2.6.4', + version = '2.6.6', description = '(Python) utility to convert medical images to jpg and png', long_description = readme(), author = 'FNNDSC',