Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation class UID/version name override and retain options #424

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions fromimage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct App {
/// (default is to replace input extension with `.new.dcm`)
#[arg(short = 'o', long = "out")]
output: Option<PathBuf>,
/// Retain the implementation class UID and version name from base DICOM
#[arg(long)]
retain_implementation: bool,
/// Print more information about the image and the output file
#[arg(short = 'v', long = "verbose")]
verbose: bool,
Expand All @@ -47,6 +50,7 @@ fn main() {
dcm_file,
img_file,
output,
retain_implementation,
verbose,
} = App::parse();

Expand Down Expand Up @@ -177,13 +181,27 @@ fn main() {

let class_uid = obj.meta().media_storage_sop_class_uid.clone();

let mut meta_builder = FileMetaTableBuilder::new()
// currently the tool will always decode the image's pixel data,
// so encode it as Explicit VR Little Endian
.transfer_syntax("1.2.840.10008.1.2.1")
.media_storage_sop_class_uid(class_uid);

// recover implementation class UID and version name from base object
if retain_implementation {
let implementation_class_uid = &obj.meta().implementation_class_uid;
meta_builder = meta_builder
.implementation_class_uid(implementation_class_uid);

if let Some(implementation_version_name) = obj.meta().implementation_version_name.as_ref() {
meta_builder = meta_builder
.implementation_version_name(implementation_version_name);
}
}

let obj = obj
.into_inner()
.with_meta(
FileMetaTableBuilder::new()
.transfer_syntax("1.2.840.10008.1.2.1")
.media_storage_sop_class_uid(class_uid),
)
.with_meta(meta_builder)
.unwrap_or_else(|e| {
tracing::error!("{}", snafu::Report::from_error(e));
std::process::exit(-3);
Expand Down
11 changes: 11 additions & 0 deletions pixeldata/src/bin/dicom-transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct App {
#[clap(flatten)]
target_ts: TargetTransferSyntax,

/// Retain the original implementation class UID and version name
#[clap(long)]
retain_implementation: bool,

/// Verbose mode
#[clap(short = 'v', long = "verbose")]
verbose: bool,
Expand Down Expand Up @@ -113,6 +117,7 @@ fn run() -> Result<(), Whatever> {
quality,
effort,
target_ts,
retain_implementation,
verbose,
} = App::parse();

Expand Down Expand Up @@ -148,6 +153,12 @@ fn run() -> Result<(), Whatever> {
std::process::exit(ERROR_TRANSCODE);
});

// override implementation class UID and version name
if !retain_implementation {
obj.meta_mut().implementation_class_uid = dicom_object::IMPLEMENTATION_CLASS_UID.to_string();
obj.meta_mut().implementation_version_name = Some(dicom_object::IMPLEMENTATION_VERSION_NAME.to_string());
}

// write to file
obj.write_to_file(output).unwrap_or_else(|e| {
eprintln!("{}", Report::from_error(e));
Expand Down
Loading