Visualizing Images From NIfTI File

Read an NIfTI file

This is example to read a NIfTI file and display an image , by using this example code you must be install package oro.nifti) first.
Download a NIfTI file from Neurohacking_data repository
library(oro.nifti)

url <- "https://raw.githubusercontent.com/muschellij2/Neurohacking_data/master/BRAINIX/NIfTI/Output_3D_File.nii.gz"
destfile <- "Output_3D_File.nii.gz"
name <- file.path(getwd(), destfile)
download.file(url, destfile,mode="wb") # NIfTI is binaryfile format
nii_T1 <- readNIfTI(destfile)
Show meta data from the file
print (nii_T1)
## NIfTI-1 format
##   Type            : nifti
##   Data Type       : 4 (INT16)
##   Bits per Pixel  : 16
##   Slice Code      : 0 (Unknown)
##   Intent Code     : 0 (None)
##   Qform Code      : 2 (Aligned_Anat)
##   Sform Code      : 2 (Aligned_Anat)
##   Dimension       : 512 x 512 x 22
##   Pixel Dimension : 0.47 x 0.47 x 5
##   Voxel Units     : mm
##   Time Units      : sec
As you see this file contain 22 images 512 x 512 pixels, one pixel using 16 bits

Visial an Slice an NIfTI file

image(nii_T1,z=11,plot.type="single") 

Visualizing All Slices
image(nii_T1)

All Planes: Coronal, Sagittal, Axial
orthographic(nii_T1,xyz=c(200,220,11)) 

Backmapping One Slice
is_btw_300_400<- ((nii_T1>300) &
(nii_T1<400))
nii_T1_mask<-nii_T1
nii_T1_mask[!is_btw_300_400]=NA
overlay(nii_T1,nii_T1_mask,z=11,plot.type="
single") 



















This example not show how to change or write NIfTI file.

Share this

Related Posts

Previous
Next Post »