| Title: | Comprehensive 'DICOM' Toolkit for Medical Imaging |
|---|---|
| Description: | A comprehensive R interface to the 'DICOM' Toolkit ('DCMTK'), providing native R bindings for reading, writing, modifying, and visualizing Digital Imaging and Communications in Medicine ('DICOM') files. Features include tidyverse-compliant data structures, 'ggplot2'-based image visualization, interactive 'Shiny' viewers, 'PACS' networking (C-ECHO, C-FIND, C-STORE, C-MOVE), structured report handling, DICOM anonymization, and integration with local and cloud-based large language models ('LLM') via 'Ollama' and 'OpenAI'-compatible APIs for AI-assisted medical image analysis. The 'DCMTK' C++ library is bundled and compiled from source, requiring no external installation. |
| Authors: | Yee How Lau [aut, cre], John Muschelli [ctb] (Original dcmtk R wrapper), OFFIS e.V. [cph] (DCMTK C++ library) |
| Maintainer: | Yee How Lau <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.1.0 |
| Built: | 2026-10-16 18:25:58 UTC |
| Source: | https://github.com/lauyeehow1986-hub/dicomtk |
Writes a valid DICOM Basic Text SR Storage (1.2.840.10008.5.1.4.1.1.88.11)
Part 10 file containing a structured report title, text content, and patient
/study identifiers.
create_dicom_sr( out_path, title = "Radiology Structured Report", text, patient_name = "ANONYMOUS", patient_id = "ANON001", study_uid = "" )create_dicom_sr( out_path, title = "Radiology Structured Report", text, patient_name = "ANONYMOUS", patient_id = "ANON001", study_uid = "" )
out_path |
Output |
title |
Document / Series title ( |
text |
Report body text ( |
patient_name |
Patient name ( |
patient_id |
Patient ID ( |
study_uid |
Optional |
Invisibly returns out_path.
sr_file <- tempfile(fileext = ".dcm") create_dicom_sr( sr_file, title = "AI Radiology Summary", text = "FINDINGS: Unremarkable brain parenchyma. IMPRESSION: Normal head CT." ) read_dicom_sr(sr_file)sr_file <- tempfile(fileext = ".dcm") create_dicom_sr( sr_file, title = "AI Radiology Summary", text = "FINDINGS: Unremarkable brain parenchyma. IMPRESSION: Normal head CT." ) read_dicom_sr(sr_file)
Standard DICOM tags with Value Representation DA (Date).
data(date_tags)data(date_tags)
A data.frame with columns tag and name.
Standard DICOM tags with Value Representation DT (DateTime).
data(datetime_tags)data(datetime_tags)
A data.frame with columns tag and name.
Exports the DICOM header and dataset elements to standard DICOMWeb JSON format (PS3.18).
dcm2json(file, out_path = NULL)dcm2json(file, out_path = NULL)
file |
Path to input DICOM file. |
out_path |
Optional output |
Character string of DICOM JSON (or invisibly out_path if written to
a file).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") json_txt <- dcm2json(dcm_file) substr(json_txt, 1, 200)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") json_txt <- dcm2json(dcm_file) substr(json_txt, 1, 200)
Extracts the binary PDF document stored in tag (0042,0011) EncapsulatedDocument.
dcm2pdf(file, out_path = tempfile(fileext = ".pdf"), opts = "", ...)dcm2pdf(file, out_path = tempfile(fileext = ".pdf"), opts = "", ...)
file |
Path to an Encapsulated PDF DICOM file. |
out_path |
Output |
opts |
Optional arguments (kept for legacy compatibility). |
... |
Additional unused arguments. |
Character string of the output .pdf file path.
Exports the DICOM header and dataset elements to XML format.
dcm2xml(file, out_path = NULL, opts = "", ...)dcm2xml(file, out_path = NULL, opts = "", ...)
file |
Path to input DICOM file. |
out_path |
Optional output |
opts |
Optional arguments (ignored in native C++ mode, kept for legacy compatibility). |
... |
Additional unused arguments. |
Character string of the output .xml file path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") xml_file <- dcm2xml(dcm_file) head(readLines(xml_file), 10)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") xml_file <- dcm2xml(dcm_file) head(readLines(xml_file), 10)
Removes or replaces Protected Health Information (PHI) tags according to HIPAA Safe Harbor and the DICOM PS3.15 Basic Application Level Confidentiality Profile. Supports date shifting, private tag removal, UID regeneration, and custom tag overrides.
dicom_anonymize( path, out_path = NULL, patient_name = "ANONYMOUS", patient_id = "ANON001", shift_days = NULL, erase_private = TRUE, regenerate_uids = TRUE, extra_remove_tags = character(), replace_tags = list() )dicom_anonymize( path, out_path = NULL, patient_name = "ANONYMOUS", patient_id = "ANON001", shift_days = NULL, erase_private = TRUE, regenerate_uids = TRUE, extra_remove_tags = character(), replace_tags = list() )
path |
Path to input DICOM file. |
out_path |
Output path for anonymized DICOM file. If |
patient_name |
Replacement string for |
patient_id |
Replacement string for |
shift_days |
Optional integer number of days to shift all date ( |
erase_private |
Logical. Remove all odd-group private tags. Default is
|
regenerate_uids |
Logical. Regenerate |
extra_remove_tags |
Optional character vector of additional tags or keywords to remove. |
replace_tags |
Named list of additional tag/value replacements. |
Invisibly returns the path to the anonymized DICOM file.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") anon_file <- dicom_anonymize(dcm_file, patient_name = "STUDY^SUBJECT01") dicom_tag_value(anon_file, c("PatientName", "PatientIdentityRemoved"))dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") anon_file <- dicom_anonymize(dcm_file, patient_name = "STUDY^SUBJECT01") dicom_tag_value(anon_file, c("PatientName", "PatientIdentityRemoved"))
Answers arbitrary questions about a DICOM file's metadata or image content using the configured LLM (or local metadata inspection).
dicom_ask(path, question, llm = dicom_llm("ollama"), include_image = FALSE)dicom_ask(path, question, llm = dicom_llm("ollama"), include_image = FALSE)
path |
Path to a DICOM file. |
question |
Character string question (e.g., |
llm |
A |
include_image |
Logical. Attach the rendered DICOM image for multimodal
vision models. Default is |
Character string answer.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_ask(dcm_file, "What is the modality and image dimensions?", llm = dicom_llm("offline"))dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_ask(dcm_file, "What is the modality and image dimensions?", llm = dicom_llm("offline"))
Compresses native uncompressed pixel data into DICOM Lossless RLE transfer
syntax (1.2.840.10008.1.2.5, per DICOM PS3.5 Annex G).
dicom_compress(path, out_path = tempfile(fileext = ".dcm"), method = c("rle"))dicom_compress(path, out_path = tempfile(fileext = ".dcm"), method = c("rle"))
path |
Input DICOM file path. |
out_path |
Output compressed DICOM file path. Defaults to a temporary
|
method |
Compression method ( |
Invisibly returns out_path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rle_file <- dicom_compress(dcm_file) file.exists(rle_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rle_file <- dicom_compress(dcm_file) file.exists(rle_file)
Creates a "dicom_connection" object holding PACS / DICOM node connection
parameters for use with dicom_echo(), dicom_find(), dicom_get(), and
dicom_send(). Supports both DIMSE TCP connections and DICOMweb (QIDO-RS /
WADO-RS / STOW-RS) HTTP endpoints.
dicom_connect( host = "127.0.0.1", port = 104L, called_ae = "ANY-SCP", calling_ae = "DICOMTK", timeout_ms = 5000L, dicomweb_url = NULL, local_dir = NULL )dicom_connect( host = "127.0.0.1", port = 104L, called_ae = "ANY-SCP", calling_ae = "DICOMTK", timeout_ms = 5000L, dicomweb_url = NULL, local_dir = NULL )
host |
Hostname or IP address of the remote DICOM peer (e.g.,
|
port |
Integer TCP port for DIMSE communication. Default is |
called_ae |
Remote Application Entity Title (Called AET). Default is
|
calling_ae |
Local Application Entity Title (Calling AET). Default is
|
timeout_ms |
Socket timeout in milliseconds. Default is |
dicomweb_url |
Optional base URL for DICOMweb (QIDO-RS / WADO-RS / STOW-RS) REST APIs. |
local_dir |
Optional local directory path to act as a local file-backed PACS repository for testing queries and retrievals offline. |
An S3 object of class "dicom_connection".
conn <- dicom_connect("127.0.0.1", port = 4242, called_ae = "ORTHANC") connconn <- dicom_connect("127.0.0.1", port = 4242, called_ae = "ORTHANC") conn
Decompresses RLE-compressed (or encapsulated) DICOM files into standard
Explicit VR Little Endian (1.2.840.10008.1.2.1) uncompressed DICOM format.
dicom_decompress(path, out_path = tempfile(fileext = ".dcm"))dicom_decompress(path, out_path = tempfile(fileext = ".dcm"))
path |
Input compressed DICOM file path. |
out_path |
Output uncompressed DICOM file path. Defaults to a temporary
|
Invisibly returns out_path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rle_file <- dicom_compress(dcm_file) dec_file <- dicom_decompress(rle_file) is_dicom(dec_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rle_file <- dicom_compress(dcm_file) dec_file <- dicom_decompress(rle_file) is_dicom(dec_file)
Renders the DICOM slice with clinical windowing to a PNG, encodes it as
base64, and sends it along with anonymized technical metadata and pixel
intensity statistics to a vision-capable LLM (e.g., Ollama llava, OpenAI
gpt-4o, or Anthropic claude-sonnet-4-20250514).
dicom_describe_image( path, llm = dicom_llm("ollama"), frame = 1L, window = "auto", prompt = NULL )dicom_describe_image( path, llm = dicom_llm("ollama"), frame = 1L, window = "auto", prompt = NULL )
path |
Path to a DICOM file. |
llm |
A |
frame |
Integer frame/slice index (1-based). Default is |
window |
Window preset ( |
prompt |
Custom instruction prompt for the vision model. |
A character string with the image description and quantitative stats.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") llm <- dicom_llm("offline") dicom_describe_image(dcm_file, llm = llm)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") llm <- dicom_llm("offline") dicom_describe_image(dcm_file, llm = llm)
Performs a DICOM Upper Layer A-ASSOCIATE-RQ handshake followed by a
Verification SOP Class (1.2.840.10008.1.1) C-ECHO-RQ over TCP, or verifies
a local directory-backed PACS connection.
dicom_echo( x, port = 104L, called_ae = "ANY-SCP", calling_ae = "DICOMTK", timeout_ms = 5000L )dicom_echo( x, port = 104L, called_ae = "ANY-SCP", calling_ae = "DICOMTK", timeout_ms = 5000L )
x |
A |
port |
Integer port (used if |
called_ae |
Called AE Title. Default is |
calling_ae |
Calling AE Title. Default is |
timeout_ms |
Timeout in milliseconds. Default is |
A tibble::tibble with columns host, port, called_ae,
success, status, message, and elapsed_ms.
conn <- dicom_connect(local_dir = system.file("extdata", package = "dicomtk")) dicom_echo(conn)conn <- dicom_connect(local_dir = system.file("extdata", package = "dicomtk")) dicom_echo(conn)
Queries a DICOM connection or local PACS directory for matching studies,
series, or instances, returning a tidy tibble::tibble that can be piped
into dplyr::filter() and dicom_get().
dicom_find(conn, level = c("STUDY", "SERIES", "IMAGE"), ...)dicom_find(conn, level = c("STUDY", "SERIES", "IMAGE"), ...)
conn |
A |
level |
Query level: |
... |
Optional tag filters as named arguments (e.g., |
A tibble::tibble of matching DICOM records.
ext_dir <- system.file("extdata", package = "dicomtk") conn <- dicom_connect(local_dir = ext_dir) dicom_find(conn)ext_dir <- system.file("extdata", package = "dicomtk") conn <- dicom_connect(local_dir = ext_dir) dicom_find(conn)
Copies or downloads matching DICOM files from a "dicom_connection" or
query result tibble into output_dir.
dicom_get(x, output_dir = tempfile("dicom_get_"), ...)dicom_get(x, output_dir = tempfile("dicom_get_"), ...)
x |
A |
output_dir |
Destination directory for retrieved |
... |
Optional filter criteria if |
Character vector of retrieved file paths in output_dir.
ext_dir <- system.file("extdata", package = "dicomtk") conn <- dicom_connect(local_dir = ext_dir) files <- conn |> dicom_find() |> dicom_get() length(files)ext_dir <- system.file("extdata", package = "dicomtk") conn <- dicom_connect(local_dir = ext_dir) files <- conn |> dicom_find() |> dicom_get() length(files)
Returns a tidy tibble describing the bundled DCMTK version, data dictionary edition, number of standard tags, and active C++ backend.
dicom_info()dicom_info()
A tibble::tibble with DCMTK configuration details.
dicom_info()dicom_info()
Creates a "dicom_llm" configuration object connecting dicomtk to:
Local Ollama (provider = "ollama", default http://localhost:11434)
OpenAI / OpenAI-compatible APIs (provider = "openai" or "custom",
supporting OpenAI, OpenRouter, LM Studio, vLLM, Azure, or local proxy
subscriptions)
Anthropic Claude (provider = "anthropic", supporting native
/v1/messages as well as OpenAI-compatible endpoints)
Offline rule-based engine (provider = "offline", for deterministic
local metadata & pixel-statistics summaries without external API calls)
dicom_llm( provider = c("ollama", "openai", "anthropic", "custom", "offline"), model = NULL, base_url = NULL, api_key = NULL, temperature = 0.2, max_tokens = 1024L, anonymize = TRUE, offline_fallback = TRUE )dicom_llm( provider = c("ollama", "openai", "anthropic", "custom", "offline"), model = NULL, base_url = NULL, api_key = NULL, temperature = 0.2, max_tokens = 1024L, anonymize = TRUE, offline_fallback = TRUE )
provider |
Character provider type: |
model |
Model identifier (e.g., |
base_url |
Optional API base URL. Defaults to |
api_key |
API key or bearer token. Automatically reads from
|
temperature |
Sampling temperature. Default is |
max_tokens |
Maximum response tokens. Default is |
anonymize |
Logical. Automatically strip HIPAA PHI tags before sending
metadata to non-local endpoints. Default is |
offline_fallback |
Logical. If |
An S3 object of class "dicom_llm".
# Local Ollama configuration local_llm <- dicom_llm("ollama", model = "llava:13b") # OpenAI-compatible configuration openai_llm <- dicom_llm("openai", model = "gpt-4o") # Anthropic Claude configuration claude_llm <- dicom_llm("anthropic", model = "claude-sonnet-4-20250514")# Local Ollama configuration local_llm <- dicom_llm("ollama", model = "llava:13b") # OpenAI-compatible configuration openai_llm <- dicom_llm("openai", model = "gpt-4o") # Anthropic Claude configuration claude_llm <- dicom_llm("anthropic", model = "claude-sonnet-4-20250514")
Updates, inserts, or deletes specified tags in a DICOM file using the native
C++ engine and writes the modified dataset to out_path.
dicom_modify( path, tags = list(), out_path = path, delete_tags = character(), erase_private = FALSE, regenerate_uids = FALSE )dicom_modify( path, tags = list(), out_path = path, delete_tags = character(), erase_private = FALSE, regenerate_uids = FALSE )
path |
Input DICOM file path. |
tags |
Named list or named character vector of tags (by |
out_path |
Output DICOM file path. Defaults to modifying |
delete_tags |
Character vector of tags or keywords to remove. |
erase_private |
Logical. Remove all odd-group private tags. Default is
|
regenerate_uids |
Logical. Generate fresh |
Invisibly returns out_path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") tmp <- tempfile(fileext = ".dcm") dicom_modify(dcm_file, tags = list(PatientName = "ANON^PATIENT"), out_path = tmp) dicom_tag_value(tmp, "PatientName")dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") tmp <- tempfile(fileext = ".dcm") dicom_modify(dcm_file, tags = list(PatientName = "ANON^PATIENT"), out_path = tmp) dicom_tag_value(tmp, "PatientName")
dcmqrdb)Scans a directory of DICOM files and builds a tidy index table organized by
Patient, Study, Series, and Instance UIDs (dcmqrdb model).
dicom_qrdb_index(directory, recursive = TRUE)dicom_qrdb_index(directory, recursive = TRUE)
directory |
Path to a directory containing DICOM files. |
recursive |
Logical. Scan subdirectories recursively. Default is |
A tibble::tibble with columns file, PatientID, PatientName,
StudyInstanceUID, StudyDate, Modality, SeriesInstanceUID,
SOPInstanceUID, Rows, and Columns.
ext_dir <- system.file("extdata", package = "dicomtk") dicom_qrdb_index(ext_dir)ext_dir <- system.file("extdata", package = "dicomtk") dicom_qrdb_index(ext_dir)
Sets up and returns a local directory-backed "dicom_connection" ready to
receive, index, and query DICOM files.
dicom_receive( output_dir = tempfile("dicom_scp_"), port = 11112L, aetitle = "DICOMTK-SCP" )dicom_receive( output_dir = tempfile("dicom_scp_"), port = 11112L, aetitle = "DICOMTK-SCP" )
output_dir |
Directory to store received DICOM files. |
port |
Port number for metadata registration. Default is |
aetitle |
Application Entity Title for the receiver. Default is
|
A "dicom_connection" object configured with local_dir = output_dir.
scp <- dicom_receive(tempfile("scp_")) scpscp <- dicom_receive(tempfile("scp_")) scp
Combines DICOM technical metadata and vision analysis to produce a
structured radiology report (EXAMINATION, TECHNIQUE, FINDINGS,
IMPRESSION), and optionally saves it as a DICOM Structured Report (.dcm)
via create_dicom_sr().
dicom_report( path, llm = dicom_llm("ollama"), frame = 1L, window = "auto", save_sr_path = NULL )dicom_report( path, llm = dicom_llm("ollama"), frame = 1L, window = "auto", save_sr_path = NULL )
path |
Path to a DICOM file. |
llm |
A |
frame |
Integer frame/slice index (1-based). Default is |
window |
Window preset. Default is |
save_sr_path |
Optional output |
A tibble::tibble with columns section and content, and the full
formatted report text in attribute "report_text".
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rpt <- dicom_report(dcm_file, llm = dicom_llm("offline")) rptdcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rpt <- dicom_report(dcm_file, llm = dicom_llm("offline")) rpt
Transmits one or more DICOM files to a configured "dicom_connection" (or
local PACS repository directory).
dicom_send(files, conn)dicom_send(files, conn)
files |
Character vector of DICOM file paths to send. |
conn |
A |
A tibble::tibble summarizing the transmission status for each file.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") pacs_dir <- tempfile("pacs_store_") dir.create(pacs_dir) conn <- dicom_connect(local_dir = pacs_dir) dicom_send(dcm_file, conn)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") pacs_dir <- tempfile("pacs_store_") dir.create(pacs_dir) conn <- dicom_connect(local_dir = pacs_dir) dicom_send(dcm_file, conn)
Generates a concise clinical and technical natural-language summary of a DICOM file's header metadata (modality, anatomy, acquisition parameters, image geometry). Automatically strips PHI tags when communicating with non-local LLM endpoints.
dicom_summarize(path, llm = dicom_llm("ollama"))dicom_summarize(path, llm = dicom_llm("ollama"))
path |
Path to a DICOM file. |
llm |
A |
A character string containing the study summary.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") llm <- dicom_llm("offline") dicom_summarize(dcm_file, llm = llm)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") llm <- dicom_llm("offline") dicom_summarize(dcm_file, llm = llm)
Checks the official upstream DCMTK GitHub mirror
(https://github.com/DCMTK/dcmtk) for new commits, dictionary releases, or
C++ module header updates, and optionally synchronizes a local dicomtk
source checkout by running tools/bundle_dcmtk.R.
dicom_sync_upstream(pkg_dir = ".", apply = FALSE, repo = "DCMTK/dcmtk")dicom_sync_upstream(pkg_dir = ".", apply = FALSE, repo = "DCMTK/dcmtk")
pkg_dir |
Optional path to a local |
apply |
Logical; if |
repo |
GitHub repository slug. Default is |
A tibble::tibble summarizing the bundled DCMTK version/commit, the latest upstream commit SHA/date/message from GitHub, and whether the bundle is up to date.
dicom_sync_upstream(apply = FALSE)dicom_sync_upstream(apply = FALSE)
Searches the 5,354-entry DCMTK 3.7.1 DICOM data dictionary by substring or
tag (GGGG,EEEE). When an llm object (created by dicom_llm()) is
supplied, natural-language questions (e.g., "What tag stores tube current?")
are also answered using the configured LLM.
dicom_tag_lookup(query, llm = NULL)dicom_tag_lookup(query, llm = NULL)
query |
Search string, tag |
llm |
Optional |
A tibble::tibble of matching DICOM dictionary entries (with an
optional "llm_explanation" attribute if llm is provided).
dicom_tag_lookup("WindowCenter") dicom_tag_lookup("(0028,1050)") dicom_tag_lookup("Patient")dicom_tag_lookup("WindowCenter") dicom_tag_lookup("(0028,1050)") dicom_tag_lookup("Patient")
Retrieves one or more tag values by tag code (e.g., "(0010,0010)") or
standard keyword (e.g., "PatientName", "Modality", "Rows").
dicom_tag_value(path, tags)dicom_tag_value(path, tags)
path |
Path to a single DICOM file. |
tags |
Character vector of tag IDs ( |
A named character vector of tag values (NA_character_ if absent).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_tag_value(dcm_file, c("Modality", "Rows", "Columns", "(0008,0070)"))dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_tag_value(dcm_file, c("Modality", "Rows", "Columns", "(0008,0070)"))
If path is provided, reads and returns the DICOM header tags present in
path as a tidy tibble. If path is NULL, returns the complete built-in
OFFIS DCMTK 3.7.1 DICOM data dictionary (5,354 tags).
dicom_tags(path = NULL, ...)dicom_tags(path = NULL, ...)
path |
Optional file or directory path to read DICOM tags from. If |
... |
Additional arguments passed to |
A tibble::tibble of DICOM tags.
# View standard DICOM dictionary dicom_tags() # Read tags from a DICOM file dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_tags(dcm_file)# View standard DICOM dictionary dicom_tags() # Read tags from a DICOM file dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_tags(dcm_file)
dcmtls)Attaches TLS certificate, private key, and CA bundle paths to a
"dicom_connection" object for secure DICOM-over-TLS communication (RFC 3240 /
DICOM PS3.15).
dicom_tls_config( conn, cert_file = NULL, key_file = NULL, ca_file = NULL, profile = c("BCP195", "BCP195-ND", "AES") )dicom_tls_config( conn, cert_file = NULL, key_file = NULL, ca_file = NULL, profile = c("BCP195", "BCP195-ND", "AES") )
conn |
A |
cert_file |
Optional path to client X.509 PEM certificate. |
key_file |
Optional path to client private key. |
ca_file |
Optional path to trusted CA certificate bundle. |
profile |
DICOM TLS security profile ( |
Updated "dicom_connection" object with TLS settings enabled.
conn <- dicom_connect("pacs.hospital.org", port = 2762) |> dicom_tls_config(profile = "BCP195") connconn <- dicom_connect("pacs.hospital.org", port = 2762) |> dicom_tls_config(profile = "BCP195") conn
Converts a single DICOM file, vector of DICOM files, directory of DICOM
slices, or "dicom_series" object into a standard NIfTI-1 (.nii or
.nii.gz) volumetric file. Uses RNifti when installed or a built-in
native NIfTI-1 binary writer with zero external dependencies.
dicom_to_nifti(path, out_path = NULL)dicom_to_nifti(path, out_path = NULL)
path |
Path to a DICOM file, directory, vector of files, or a
|
out_path |
Output |
Invisibly returns out_path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") nii_file <- dicom_to_nifti(dcm_file) file.exists(nii_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") nii_file <- dicom_to_nifti(dcm_file) file.exists(nii_file)
Renders a DICOM slice with window/level transformation to a PNG image file.
dicom_to_png( path, out_path = tempfile(fileext = ".png"), frame = 1L, window = "auto", width = NULL, height = NULL )dicom_to_png( path, out_path = tempfile(fileext = ".png"), frame = 1L, window = "auto", width = NULL, height = NULL )
path |
Path to a DICOM file, or a |
out_path |
Output PNG file path. Defaults to a temporary |
frame |
Integer frame/slice index (1-based). Default is |
window |
Window preset name (e.g., |
width, height
|
Output PNG dimensions in pixels. Defaults to the native DICOM image dimensions. |
Invisibly returns out_path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") png_file <- dicom_to_png(dcm_file) file.exists(png_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") png_file <- dicom_to_png(dcm_file) file.exists(png_file)
dcmsign)Checks whether a DICOM dataset contains digital signatures in
DigitalSignaturesSequence (FFFA,FFFA) or MACParametersSequence (4FFE,0001)
and returns a tidy summary tibble.
dicom_verify_signature(path)dicom_verify_signature(path)
path |
Path to a DICOM file. |
A tibble::tibble of signature elements (0 rows if unsigned).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_verify_signature(dcm_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") dicom_verify_signature(dcm_file)
Launches a Shiny web application for interactive exploration of DICOM files and multi-slice series, featuring slice scrolling, CT window/level presets, custom Window Center & Width sliders, colormap toggling, and a searchable DICOM header tag inspector.
dicom_viewer(path = NULL, launch.browser = interactive(), ...)dicom_viewer(path = NULL, launch.browser = interactive(), ...)
path |
Optional file or directory path to preload in the viewer. Defaults to the bundled example DICOM file. |
launch.browser |
Logical. Launch in browser/viewer pane. Default is
|
... |
Additional arguments passed to |
Invisibly returns the Shiny application object (or runs the app if interactive).
if (interactive()) { dicom_viewer() }if (interactive()) { dicom_viewer() }
Applies linear window/level (Window Center and Window Width) transformation
to a DICOM pixel matrix or array, normalizing output values to [0, 1].
Supports standard clinical CT window presets ("brain", "lung", "bone",
"abdomen", "mediastinum", "liver", "stroke", "subdural", "angio"),
embedded DICOM WindowCenter/WindowWidth tags ("auto"), or custom
numeric center and width.
dicom_window(x, center = NULL, width = NULL, preset = "auto", invert = NULL)dicom_window(x, center = NULL, width = NULL, preset = "auto", invert = NULL)
x |
A |
center |
Numeric window center (level). Overrides |
width |
Numeric window width (must be |
preset |
Character preset name ( |
invert |
Optional logical to invert grayscale intensities. By default,
automatically inverts if |
A numeric matrix/array of the same dimensions as x with values
scaled to [0, 1].
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") px <- read_dicom_pixels(dcm_file) win_auto <- dicom_window(px, preset = "auto") range(win_auto)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") px <- read_dicom_pixels(dcm_file) win_auto <- dicom_window(px, preset = "auto") range(win_auto)
dcmwlm)Reads or constructs a tidy Modality Worklist (MWL) schedule table containing
ScheduledProcedureStepSequence (0040,0100) attributes (Modality,
ScheduledStationAETitle, ScheduledProcedureStepStartDate, PatientName,
PatientID, AccessionNumber).
dicom_worklist(path = NULL)dicom_worklist(path = NULL)
path |
Optional path to a DICOM worklist |
A tibble::tibble representing Modality Worklist scheduled items.
dicom_worklist()dicom_worklist()
Alias for plot_dicom() designed for composable ggplot2 pipelines.
ggdicom(x, frame = 1L, window = "auto", ...)ggdicom(x, frame = 1L, window = "auto", ...)
x |
Path to a DICOM file, a |
frame |
Integer slice/frame index (1-based) when |
window |
Window preset ( |
... |
Additional arguments passed to |
A ggplot2::ggplot object.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") ggdicom(dcm_file, palette = "viridis")dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") ggdicom(dcm_file, palette = "viridis")
Returns TRUE if the bundled DCMTK C++ engine and data dictionary are
initialized and ready.
have_dcmtk()have_dcmtk()
A logical scalar (TRUE).
have_dcmtk()have_dcmtk()
Inspects the file header for the standard 128-byte preamble + "DICM" magic
bytes or valid initial DICOM group/element tags.
is_dicom(path)is_dicom(path)
path |
Character vector of file paths. |
A logical vector of the same length as path.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") is_dicom(dcm_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") is_dicom(dcm_file)
dcmtk
Backward-compatible wrappers for functions in the original dcmtk R package
(dcmdump, dcmdump_full, dcmhd, wide_hdr, burned_annot, dcmodify,
dcm_anon, dcm_subtract_date, dcmj2pnm, dcmdjpeg, dcmdrle,
dcmcrle, check_dcmtk_cmd), now powered by the native dicomtk C++17
engine without requiring external CLI binaries.
dcmdump(file, ...) dcmdump_full(file, ...) dcmhd(file, ...) wide_hdr(hdr, ...) burned_annot(file, ...) dcmodify(file, tags = list(), outfile = file, ...) dcm_anon(file, outfile = NULL, ...) dcm_subtract_date(file, outfile = NULL, shift_days = -365L, ...) dcmj2pnm(file, outfile = tempfile(fileext = ".png"), opts = "--write-png", ...) dcmdjpeg(file, outfile = tempfile(fileext = ".dcm"), ...) dcmdrle(file, outfile = tempfile(fileext = ".dcm"), ...) dcmcrle(file, outfile = tempfile(fileext = ".dcm"), ...) check_dcmtk_cmd(cmd = "dcmdump")dcmdump(file, ...) dcmdump_full(file, ...) dcmhd(file, ...) wide_hdr(hdr, ...) burned_annot(file, ...) dcmodify(file, tags = list(), outfile = file, ...) dcm_anon(file, outfile = NULL, ...) dcm_subtract_date(file, outfile = NULL, shift_days = -365L, ...) dcmj2pnm(file, outfile = tempfile(fileext = ".png"), opts = "--write-png", ...) dcmdjpeg(file, outfile = tempfile(fileext = ".dcm"), ...) dcmdrle(file, outfile = tempfile(fileext = ".dcm"), ...) dcmcrle(file, outfile = tempfile(fileext = ".dcm"), ...) check_dcmtk_cmd(cmd = "dcmdump")
file |
Path to DICOM file(s). |
... |
Additional arguments passed to modern |
hdr |
A header data frame or tibble returned by |
tags |
Named list of tags and values to modify. |
outfile |
Optional output file path. |
shift_days |
Integer number of days to shift dates (default |
opts |
Optional command-line style options (ignored in native C++ mode). |
cmd |
Command name. |
Queries the local Ollama daemon (GET /api/tags) and returns a tidy
tibble::tibble of installed models (name, size_gb, modified_at).
Returns an empty tibble if Ollama is not running.
ollama_list_models( base_url = Sys.getenv("OLLAMA_HOST", unset = "http://localhost:11434") )ollama_list_models( base_url = Sys.getenv("OLLAMA_HOST", unset = "http://localhost:11434") )
base_url |
Ollama base URL. Defaults to |
A tibble::tibble with columns name, size_gb, and modified_at.
ollama_list_models()ollama_list_models()
Renders a 2D slice of a DICOM image as a ggplot2::ggplot object with clinical window/level scaling, proper pixel aspect ratio, and optional radiological metadata overlay.
plot_dicom( x, frame = 1L, window = "auto", center = NULL, width = NULL, palette = c("gray", "viridis", "inferno", "magma", "plasma"), annotate = TRUE, title = NULL )plot_dicom( x, frame = 1L, window = "auto", center = NULL, width = NULL, palette = c("gray", "viridis", "inferno", "magma", "plasma"), annotate = TRUE, title = NULL )
x |
Path to a DICOM file, a |
frame |
Integer slice/frame index (1-based) when |
window |
Window preset ( |
center, width
|
Optional explicit window center and width. |
palette |
Color palette: |
annotate |
Logical. Display clinical overlay text (modality, dimensions,
window center/width). Default is |
title |
Optional plot title. |
A ggplot2::ggplot object.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") p <- plot_dicom(dcm_file) pdcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") p <- plot_dicom(dcm_file) p
Reads one or more DICOM files (or directories of DICOM files) using the native C++17 / DCMTK parser and returns a tidy tibble::tibble.
read_dicom(path, wide = FALSE, include_sequences = FALSE, recursive = TRUE)read_dicom(path, wide = FALSE, include_sequences = FALSE, recursive = TRUE)
path |
Character vector of DICOM file paths or directory paths. |
wide |
Logical. If |
include_sequences |
Logical. If |
recursive |
Logical. When |
A tibble::tibble of class c("dicom_tbl", "tbl_df", "tbl", "data.frame").
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") hdr <- read_dicom(dcm_file) hdr # Wide format (1 row per file) read_dicom(dcm_file, wide = TRUE)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") hdr <- read_dicom(dcm_file) hdr # Wide format (1 row per file) read_dicom(dcm_file, wide = TRUE)
dcmtract) and Enhanced Multi-Frame IODs (dcmect / dcmfg)Extracts functional groups (SharedFunctionalGroupsSequence (5200,9229),
PerFrameFunctionalGroupsSequence (5200,9230)) and tractography sequences
(TrackSetSequence (0066,0101)) into a tidy tibble::tibble.
read_dicom_ect(path)read_dicom_ect(path)
path |
Path to a DICOM Enhanced CT or Tractography file. |
A tibble::tibble of functional group and tractography elements.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") read_dicom_ect(dcm_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") read_dicom_ect(dcm_file)
Reads the header elements of one or more DICOM files into a tidy tibble.
Compatible with both dicomtk tidy pipelines and legacy dcmtk::read_dicom_header()
arguments.
read_dicom_header( file, replace_names = FALSE, add_opts = NULL, verbose = FALSE, wide = FALSE, ... )read_dicom_header( file, replace_names = FALSE, add_opts = NULL, verbose = FALSE, wide = FALSE, ... )
file |
Character vector of DICOM file paths or directory paths. |
replace_names |
Logical. Kept for compatibility with legacy |
add_opts |
Character vector of options (ignored in native C++ mode, kept for backward compatibility). |
verbose |
Logical. Print progress information. Default is |
wide |
Logical. Return wide format (1 row per file). Default is |
... |
Additional arguments passed to |
A tibble::tibble containing the parsed DICOM header elements.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") read_dicom_header(dcm_file)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") read_dicom_header(dcm_file)
Reads and decodes 8-bit, 16-bit, or 32-bit monochrome or RGB pixel data
(including RLE-compressed frames) directly into an R matrix or array, applying
Modality LUT (RescaleSlope and RescaleIntercept) when rescale = TRUE.
read_dicom_pixels(path, frame = 0L, rescale = TRUE)read_dicom_pixels(path, frame = 0L, rescale = TRUE)
path |
Path to a single DICOM file. |
frame |
Integer frame number (1-indexed). Use |
rescale |
Logical. Apply |
A numeric matrix [rows, cols] (for single-frame monochrome) or
3D/4D array [rows, cols, frames/channels] with class "dicom_pixels" and
DICOM imaging metadata attached as attributes.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") px <- read_dicom_pixels(dcm_file) dim(px)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") px <- read_dicom_pixels(dcm_file) dim(px)
dcmpmap)Reads a DICOM Parametric Map (PMAP) dataset and applies RealWorldValueSlope
and RealWorldValueIntercept transformations.
read_dicom_pmap(path)read_dicom_pmap(path)
path |
Path to a DICOM Parametric Map file. |
A list of class "dicom_pmap" containing values (real-world mapped
numeric array) and metadata (tibble of header tags).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") pmap <- read_dicom_pmap(dcm_file) dim(pmap$values)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") pmap <- read_dicom_pmap(dcm_file) dim(pmap$values)
dcmpstat)Extracts display shutter, VOI LUT, graphic annotation (0x0070), and spatial
transformation parameters from a DICOM Presentation State (PR) object.
read_dicom_pstate(path)read_dicom_pstate(path)
path |
Path to a DICOM Presentation State file. |
A list of class "dicom_pstate" containing annotations (group
0x0070 elements), voi_lut (window/LUT attributes), and header.
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") ps <- read_dicom_pstate(dcm_file) psdcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") ps <- read_dicom_pstate(dcm_file) ps
dcmrt)Reads DICOM Radiation Therapy objects (RTPLAN, RTDOSE, RTSTRUCT,
RTIMAGE), extracting group 0x3002, 0x3004, 0x3006, 0x3008, 0x300A,
and 0x300C elements and nested sequences into a tidy tibble::tibble, along
with dose grids if pixel data is present (RTDOSE).
read_dicom_rt(path)read_dicom_rt(path)
path |
Path to a DICOM RT file. |
A list of class "dicom_rt" containing modality, summary (tidy
tibble of top-level RT attributes), rt_elements (full hierarchical RT
sequence tibble), and dose_grid (3D dose array if Modality == "RTDOSE").
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rt_info <- read_dicom_rt(dcm_file) rt_info$modalitydcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") rt_info <- read_dicom_rt(dcm_file) rt_info$modality
dcmseg)Reads a DICOM Segmentation (SEG) dataset, extracting segment descriptions
(SegmentSequence (0062,0002)) and the binary/fractional 3D segmentation
mask array.
read_dicom_seg(path)read_dicom_seg(path)
path |
Path to a DICOM Segmentation file. |
A list of class "dicom_seg" containing segments (tibble of
segment metadata) and mask (pixel/voxel mask array).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") seg <- read_dicom_seg(dcm_file) dim(seg$mask)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") seg <- read_dicom_seg(dcm_file) dim(seg$mask)
Scans a directory (or vector of DICOM file paths), reads slice headers and
pixel data, orders slices spatially by InstanceNumber or
ImagePositionPatient, and assembles a 3D numeric array [rows, cols, slices]
alongside a wide metadata tibble.
read_dicom_series(path, recursive = TRUE, rescale = TRUE)read_dicom_series(path, recursive = TRUE, rescale = TRUE)
path |
Directory path or character vector of DICOM file paths. |
recursive |
Logical. Search subdirectories recursively. Default is |
rescale |
Logical. Apply |
An object of class "dicom_series" (a named list with elements
volume ([rows, cols, slices] numeric array), metadata (wide tibble of
slice headers), and dims (integer vector)).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") series <- read_dicom_series(c(dcm_file, dcm_file)) dim(series$volume)dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") series <- read_dicom_series(c(dcm_file, dcm_file)) dim(series$volume)
Parses a DICOM Structured Report (dcmsr) or hierarchical DICOM dataset
(including RT Plan/Dose/Structure Set, Segmentation, Parametric Map, and
Tractography objects) into a tidy tibble::tibble preserving sequence
hierarchy (depth and sequence_path).
read_dicom_sr(path)read_dicom_sr(path)
path |
Path to a DICOM Structured Report ( |
A tibble::tibble with columns depth, sequence_path, tag,
keyword, vr, and value.
sr_file <- tempfile(fileext = ".dcm") create_dicom_sr( sr_file, title = "Chest CT Report", text = "No acute cardiopulmonary abnormality." ) read_dicom_sr(sr_file)sr_file <- tempfile(fileext = ".dcm") create_dicom_sr( sr_file, title = "Chest CT Report", text = "No acute cardiopulmonary abnormality." ) read_dicom_sr(sr_file)
dcmtract)Reads a DICOM Tractography Results (1.2.840.10008.5.1.4.1.1.66.6) dataset,
extracting TrackSetSequence (0066,0101) and streamline metadata into a tidy
tibble::tibble.
read_dicom_tract(path)read_dicom_tract(path)
path |
Path to a DICOM Tractography file. |
A list of class "dicom_tract" containing track_sets (tibble of
group 0x0066 elements) and header (top-level metadata tibble).
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") tr <- read_dicom_tract(dcm_file) trdcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") tr <- read_dicom_tract(dcm_file) tr
Standard DICOM tags containing Protected Health Information (PHI) targeted for removal or replacement during anonymization.
data(removal_tags)data(removal_tags)
A data.frame with columns tag and name.
Visualizes a 3D DICOM series ("dicom_series" or 3D numeric array) using:
"mpr": 3-plane Orthogonal Multi-Planar Reconstruction (Axial, Coronal,
Sagittal slices) via ggplot2.
"mip": Maximum Intensity Projection across Axial, Coronal, and Sagittal
orientations via ggplot2.
"rgl": Interactive 3D voxel rendering using the rgl package (falls back
to "mip" if rgl is not installed).
render_volume( x, method = c("mpr", "mip", "rgl"), window = "auto", threshold = 0.5, palette = c("gray", "viridis", "inferno", "magma", "plasma") )render_volume( x, method = c("mpr", "mip", "rgl"), window = "auto", threshold = 0.5, palette = c("gray", "viridis", "inferno", "magma", "plasma") )
x |
A |
method |
Visualization mode: |
window |
Window preset ( |
threshold |
Optional intensity threshold in |
palette |
Color palette ( |
A ggplot2::ggplot object (for "mpr" and "mip") or invisibly the
rgl scene ID (for "rgl").
dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") series <- read_dicom_series(c(dcm_file, dcm_file, dcm_file)) render_volume(series, method = "mpr") render_volume(series, method = "mip")dcm_file <- system.file("extdata", "example.dcm", package = "dicomtk") series <- read_dicom_series(c(dcm_file, dcm_file, dcm_file)) render_volume(series, method = "mpr") render_volume(series, method = "mip")
Creates a standard DICOM Part 10 Explicit VR Little Endian file from an R 2D matrix or 3D array of pixel values and an optional named list or character vector of DICOM metadata tags.
write_dicom(x, path, metadata = list())write_dicom(x, path, metadata = list())
x |
A numeric 2D matrix |
path |
Output file path for the written |
metadata |
Named list or named character vector of DICOM tags/keywords
and values (e.g., |
Invisibly returns the normalized output path.
mat <- matrix(seq(0, 255), nrow = 16, ncol = 16) out <- tempfile(fileext = ".dcm") write_dicom(mat, out, metadata = list(PatientName = "TEST^PATIENT", Modality = "CT")) read_dicom(out, wide = TRUE)mat <- matrix(seq(0, 255), nrow = 16, ncol = 16) out <- tempfile(fileext = ".dcm") write_dicom(mat, out, metadata = list(PatientName = "TEST^PATIENT", Modality = "CT")) read_dicom(out, wide = TRUE)