Crates.io | nu_plugin_dcm |
lib.rs | nu_plugin_dcm |
version | 0.1.8 |
source | src |
created_at | 2021-07-24 17:37:33.371168 |
updated_at | 2022-09-08 20:46:49.655705 |
description | A nushell plugin to parse Dicom files |
homepage | https://github.com/realcundo/nu_plugin_dcm |
repository | https://github.com/realcundo/nu_plugin_dcm |
max_upload_size | |
id | 426863 |
size | 69,133 |
Note that this plugin works with nu>=0.60. If you want to use nu<=0.44, use version 0.1.3 of this plugin.
A nushell plugin to parse Dicom objects.
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. One notable limitation is that all Dicom objects are expected to have a preamble.
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.
dcm
plugin reads its input from single values or from specific columns:
dcm
: expects a string/filename or binary Dicom datadcm $column_name
: reads a string/filename or binary Dicom data from $column
. This is
equivalent to get $column | dcm
.dcm
plugin works in two modes:
--error
option is used. This will report all errors in the specified column. Empty column value means no error.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.
echo file.dcm | dcm # uses filename/string to specify which file to open
open file.dcm | dcm # pass binary data to `dcm`
ls file.dcm | dcm name # use `name` column as the filename
echo file.dcm | wrap foo | dcm foo # use `foo` column as the filename
open file.dcm | wrap foo | dcm foo # use `foo` column as binary data
open file.dcm | dcm | to json --indent 2
open file.dcm | dcm | to yaml
ls *.dcm | dcm name | to json --indent 2
ls *.dcm | dcm name | to yaml
ls **/* |
where type == file |
dcm name -e error |
where error == "" |
group-by Modality
PixelSpacing is an array with 2 values.
To flatten the array use .0
and .1
indices.
let files = (ls | where type == file)
echo $files |
select name size |
merge {
echo $files |
dcm name -e error |
default "" SOPInstanceUID |
select SOPInstanceUID Modality PixelSpacing.0 PixelSpacing.1 error
} |
sort-by size
Note that when a file cannot be parsed, it won't have SOPInstanceUID
column. The default
commands makes sure that select
can find the column.
You can also use each
and par-each
like in the following example.
Use par-each
to process files in parallel:
ls **/* |
par-each { |it| {
name: $it.name,
size: $it.size,
sha256: (open $it.name | hash sha256),
dcm: ($it.name | dcm -e error)
} } |
select name size sha256 dcm.Modality dcm.SOPInstanceUID dcm.error |
sort-by name
Build and install using cargo:
cargo install nu_plugin_dcm
and then register in nu via
register --encoding=json <PATH-TO-nu_plugin_dcm>/nu_plugin_dcm
Note that you must use json
encoding. capnp
is not supported yet.