nu_plugin_dcm
A nushell plugin to parse DICOM objects.
Compatibility Matrix
| nushell version | nu_plugin_dcm version |
|---|---|
| 0.108.x | 0.8.x |
| 0.107.x | 0.5.x |
| 0.106.x | 0.4.x |
| 0.105.x | 0.3.2 |
| 0.60.x | 0.1.8 |
Also note that this version is not fully compatible with 0.2.x and earlier versions of this plugin. The main difference
is that ls *.dcm | dcm name doesn't work anymore.
Use ls *.dcm | dcm, ls *.dcm | get name or ls *.dcm | select name type | dcm instead. dcm name is now reserved
for the future to select dicom tags.
This plugin is in the early stage of the development. It is usable, but it might not be able to cope with all DICOM objects or DICOMweb records. See Known limitations for details.
I'm still trying to figure out what is the most useful way of using this plugin. Please feel free to try it out, send feedback in Discussions or report problems in Issues.
Usage
dcm plugin reads its input from single values or from list of values:
dcm: expects a string/filename, file record (must containnameandtype), DICOMweb record, or binary DICOM datals *.dcm | dcm: process a list of files, resulting in a list of dicom recordsls *.dcm | select name type | dcm: process a list of files specified by their filename, resulting in a list of dicom recordsopen --raw file.dcm | into binary | dcm: process a binary stream, resulting in a dicom recordopen dicomweb.json | dcm: process a dicomweb record, resulting in a dicom record
See Examples for more details.
Error handling
dcm plugin works in two modes:
- default, when errors are reported as error rows, reported by nu,
- when
--erroroption is used, errors are reported in provided column. If there were no errors, the column value is empty.
Known Limitations
-
DICOM objects without a preamble and DCIM header will fail to load.
-
PixelData is always skipped. For now I'm considering this to be a feature that speeds up DICOM parsing.
-
dcmcan process binary data. You can pass it directly todcmasopen --raw file.dcm | dcm. However, when passing a list of binary streams,nushellwill try to convert it to a list of strings. To work around this, useinto binary, e.g.:| ) | ) |Without
into binary,dcmwould see a list of strings, assuming it's a list of filenames. -
For DICOMweb inputs, only the first of "Alphabetic", "Ideographic", "Phonetic" Patient Names is extracted.
-
For DICOMweb inputs,
BulkDataURIandInlineBinaryare not extracted andnothingis returned as their values.
Examples
Output DICOM file as a record/table (list of records)
| | | | | | | | # ls file.dcm | select name | dcm # fails because the record only contains `name` field.
| |
Dump DICOM file as a JSON/YAML document
| |
| |
Dump all DICOM files in the current directory to a JSON/YAML document
| |
| |
Find all files in the current directory and subdirectories, parse them, and group by Modality
|
|
|
|
|
For each file in the current directory, show the filename, file size, SOP Instance UID, and Modality, and sort by SOP Instance UID
|
|
|
|
) |
Note that when a file cannot be parsed, it won't have SOPInstanceUID, etc. columns. Without --ignore-errors select
would fail since selected columns are missing. Another option would be using default "" SOPInstanceUID to add values
for missing columns.)
For each file in all subdirectories, show filename, file size, SHA256 hash of the file, SOP Instance UID, and a DICOM parsing error, if any
Use par-each to process files in parallel:
| |
|
|
Installation
Build and install using cargo:
and then register in nu, e.g.
plugin add ~/.cargo/bin/nu_plugin_dcm
To start using it without restarting nu, you can import it:
plugin use ~/.cargo/bin/nu_plugin_dcm