library(oro.dicom)
## Warning: 程辑包'oro.dicom'是用R版本4.2.3 来建造的
## oro.dicom 0.5.3
library(tiff)
url <- "https://raw.githubusercontent.com/muschellij2/Neurohacking_data/master/BRAINIX/DICOM/T1/IM-0001-0001.dcm"
destfile <- "IM-0001-0001.dcm"
name <- file.path(getwd(), destfile)
download.file(url, destfile,mode="wb") # DICOM is binaryfile format
destfile
## [1] "IM-0001-0001.dcm"
dcm <- readDICOMFile(destfile)
names(dcm)
## [1] "hdr" "img"
image(t(dcm$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="",
      main="Example image from DICOM file")

tiff_file <- "C:\\Users\\liyix\\OneDrive\\Desktop\\file22.tiff"
tiff(file = tiff_file, width = 8, height = 6, units = "cm", res = 300)

image(t(dcm$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="",
      main="Example image from DICOM file")
dev.off()
## png 
##   2
# Save DICOM image as PDF
pdf_file <- "C:\\Users\\liyix\\OneDrive\\Desktop\\file22.pdf"
pdf(file = pdf_file, width = 8, height = 6)  # You can adjust width and height as needed

image(t(dcm$img), col=grey(0:64/64), axes=FALSE, xlab="", ylab="",
      main="Example image from DICOM file")

# Add any other elements or annotations as needed

dev.off()  # Close the PDF device
## png 
##   2