Convert DICOM images to PGM/PPM, PNG, JPEG or BMP using dcmdump from DCMTK

dcmj2pnm(file, outfile = tempfile(fileext = ".png"),
  opts = "--write-png", ...)

Arguments

file

DICOM file name

outfile

output file name passed to dcmtk_cmd

opts

opts passed to dcmtk_cmd

...

options passed to dcmtk_cmd intern

Value

Character vector of information

Examples

if (!have_dcmtk_cmd("dcmj2pnm")) {
  install_dir = tempdir()
  res = try({
    install_dcmtk(install_dir = install_dir)
  })
  if (inherits(res, "try-error")) {
    res = FALSE
  }
  if (!res) {
    source_install_dcmtk(install_dir = install_dir)
  }
  options(dcmtk.path = install_dir)
}
file = system.file("extdata", "example.dcm", package = "dcmtk")
png_file = dcmj2pnm(file)
#> /tmp/RtmpbIKxLr/bin/dcmj2pnm  /home/runner/work/_temp/Library/dcmtk/extdata/example.dcm --write-png  '/tmp/RtmpbIKxLr/file8df94a32612e.png'
print(png_file)
#> [1] "/tmp/RtmpbIKxLr/file8df94a32612e.png"
#> attr(,"input_file")
#> [1] "/home/runner/work/_temp/Library/dcmtk/extdata/example.dcm"
print(file.exists(png_file))
#> [1] FALSE
print(normalizePath(png_file))
#> Warning: path[1]="/tmp/RtmpbIKxLr/file8df94a32612e.png": No such file or directory
#> [1] "/tmp/RtmpbIKxLr/file8df94a32612e.png"
img = png::readPNG(png_file)
#> Error in png::readPNG(png_file) unable to open /tmp/RtmpbIKxLr/file8df94a32612e.png
plot(1:2, type='n')

image(img)
#> Error in image(img) object 'img' not found