SlideShare a Scribd company logo
1 of 18
Download to read offline
Developing S4 Classes
for Medical Imaging Data
  Initial Experience(s)
       Brandon Whitcher, PhD
           GlaxoSmithKline
       Clinical Imaging Centre
Acknowledgements
• S4 Classes and Methods
  – Slides by F. Leisch and P. Murrell
  – Software for Data Analysis by J. Chambers
  – R Programming for Bioinformatics by R. Gentlemen
  – R packages
     • nlme
     • kernlab
     • EBImage




                                                       2
OOP and Classes in R
• One identifies real objects, and the operations on them,
  that are interesting.
   – These operations can be systematically implemented.
• A basic principle (hope) is that by faithfully
  representing the objects we get easier-to-implement
  functions.
• A class is an abstract definition of a concrete real-world
  object.
• A class system is a software infrastructure that is
  designed to help construct classes and to provide
  programmatic support for dealing with classes.

                                                           3
Why (S4) Classes for Medical
            Imaging Data?
• Context of imaging data
• Interface with data standards and third-party
  software
• Numerous processing steps involved
   – Multiple information sources
• Audit trail (internal and external agencies)
• Too easy to make mistakes!


                                                  4
Data Analysis Pipeline

                                            Test statistics
       Motion correction   Model building
                                              p-values
           Warping          Parameter
                                              Multiple
        Co-registration     estimation
                                            comparisons


Data
                           Mathematical     Statistical
       Pre-processing
                            Modelling       Analysis

                                                              Results



                                                                   5
Medical Imaging Data
                                     Slice Thickness; e.g. 5mm



Z


                                                                          Y


                  X


                                                       X

Chosen parameters depend
                                             Spatial Resolution
on many factors: application,                Size = X × Y; e.g. 256×256
scanner, local practice,
radiologist preferences, etc.   e.g. 0.4mm                           6
Composition of Structural Data


                               NIfTI 3D




                 convert
                                              Z

                           X
                                    Y

                                          7
    DICOM
Composition of Dynamic Data



               •••




               •••
           Z                   Z
                                   NIfTI 4D
 X                   X
       Y                   Y


 t=1           •••   t=T                      8
The nifti Class
• Inherits from class array
• Contains 44 “slots” (not counting .Data)
   – both numeric and character strings [348 bytes]
       setClass(“nifti”, representation(“sizeof_hdr”=“numeric”,
                                        “data_type”=“character”,
                                        ...),
                         prototype(“sizeof_hdr”=348,
                                   “data_type”=“”,
                                   ...),
                         contains=“array”)


• Also created function nifti() for user-defined slots.
• Similar class has been defined for ANALYZE data.

                                                                   9
Method “show” for nifti Class
    setMethod(“show”, “nifti”, function(object) {
      cat(“NIfTI-1 file format”, fill=TRUE)
      cat(...)
      cat(...)
    })

    > ffd
    NIfTI-1 format
      Type              :   nifti
      Data Type         :   4 (INT16)
      Bits per Pixel    :   16
      Slice Code        :   0 (Unknown)
      Intent Code       :   0 (None)
      Qform Code        :   1 (Scanner_Anat)
      Sform Code        :   0 (Unknown)
      Dimension         :   64 x 64 x 21 x 180
      Pixel Dimension   :   4 x 4 x 6 x 3
      Voxel Units       :   mm
      Time Units        :   sec



                                                    10
Validity Checking for nifti Class
  setValidity(“nifti”, function(object) {
    retval <- NULL
    ...
    if (object@”sizeof_hdr” != 348)
      retval <- c(retval, “sizeof_hdr != 348”)
    if (!object@datatype %in% c(2^(1:11),768,1280,1536,1792))
      retval <- c(retval, “datatype not recognized”)
    ...
    if (!all(object@”dim_”[indices] == dim(object@.Data)))
      retval <- c(retval, “dim/img mismatch”)
    ...
    if (is.null(retval))
      return(TRUE)
    else
      return(retval)
  })




                                                                11
Manipulation of Slots
• The nifti header allows limited text information
    – descrip (80 characters) and aux_file (24 characters)
    Slots                                 Acessor functions
    > mniLR@”aux_file”                    > aux.file(mniLR)
    [1] "none                   "         [1] "none                   "
    > mni@”descrip”                       > descrip(mniLR)
    [1] "FSL3.2beta"                      [1] "FSL3.2beta"


    – Replacement functions
setMethod(“descrip”, “nifti”, function(object) { object@descrip })
setGeneric(“descrip<-”, function(x, value) { standardGeneric(“descrip<-”) })
setReplaceMethod(“descrip”, “nifti”,
                 function(x, value) {
                   x@descrip <- value
                   x
                 })
                                                                          12
Additional Methods
• readNIfTI() and writeNIfTI()
   – IO functions for NIfTI data (100% R)
   – Affine transformations
• image()
   – Forces S3 method into proper generic method
   – Equivalent to a “lightbox” representation
• overlay()
   – Essentially, the image function for two input arrays
• orthographic()
   – 2×2 matrix of plots: coronal, sagittal, axial
   – Utilizes “pixel dimension” slot

                                                            13
ffd <- readNIfTI(“filtered_func_data.nii.gz”)
image(ffd, zlim=range(ffd)) # Figure 1
zstat1 <- readNIfti(“zstat1.nii.gz”)
overlay(ffd, ifelse(abs(zstat1) > 5, zstat1, NA), zlim.x=range(ffd)) # Figure 2




                                                                           14
mni <- readNIfTI(“avg152T1_LT_nifti.nii.gz”)
orthographic(mni, zlim=range(mni))
> mniLR
NIfTI-1 format
  Type            : nifti
  Data Type       : 2 (UINT8)
  Bits per Pixel : 8
  Slice Code      : 0 (Unknown)
  Intent Code     : 0 (None)
  Qform Code      : 0 (Unknown)
  Sform Code      : 4 (MNI_152)
  Dimension       : 91 x 109 x 91
  Pixel Dimension : 2 x 2 x 2
  Voxel Units     : mm
  Time Units      : sec




                                               15
Coercion and Extensions
• Coercion
   – Implicit since nifti class is built on the array class.
                      > A <- array(1:8^3, rep(8,3))
                      > B <- as(A, “nifti”)
                      > dim(B)
                      [1] 8 8 8
                      > B@”dim_”
                      [1] 0 0 0 0 0 0 0 0
   – But... it will fail validObject().
• Allow extensions via the NIfTI-1.1 mechanism.
   – Define new class “niftiExtension”
   – Implement full audit trail
       • XML document – library(“XML”)

                                                               16
Conclusions
• S4 classes are powerful
   – Robust framework
   – Generics and methods
   – Validity checking
   – Inheritance
• ... and difficult
   – Documentation (lack thereof)
   – Examples (lack thereof)
   – Slower than S3 (?)

                                    17
Todo List
• Integrate S4 class into image analysis functions.
  – Modification of .Data causes modification of slot(s)
• Use cniftilib to be 100% NIfTI compliant
  – Rniftilib by Oliver Granert <o.granert@neurologie.uni-kiel.de>
• Medical_Imaging task view
  – Seven packages in current version.




                                                                     18

More Related Content

What's hot

Introduction to deep learning using python
Introduction to deep learning using pythonIntroduction to deep learning using python
Introduction to deep learning using pythonLino Coria
 
机器学习Adaboost
机器学习Adaboost机器学习Adaboost
机器学习AdaboostShocky1
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - RevisionAhmed Gad
 
Session 06 machine learning.pptx
Session 06 machine learning.pptxSession 06 machine learning.pptx
Session 06 machine learning.pptxbodaceacat
 
Software tookits for machine learning and graphical models
Software tookits for machine learning and graphical modelsSoftware tookits for machine learning and graphical models
Software tookits for machine learning and graphical modelsbutest
 
Java7 Garbage Collector G1
Java7 Garbage Collector G1Java7 Garbage Collector G1
Java7 Garbage Collector G1Dmitry Buzdin
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsiqbalphy1
 
Generative adversarial networks
Generative adversarial networksGenerative adversarial networks
Generative adversarial networksKyuri Kim
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonMicrosoft
 
08 ds and algorithm session_11
08 ds and algorithm session_1108 ds and algorithm session_11
08 ds and algorithm session_11Niit Care
 
Anomaly Detection and Localization Using GAN and One-Class Classifier
Anomaly Detection and Localization  Using GAN and One-Class ClassifierAnomaly Detection and Localization  Using GAN and One-Class Classifier
Anomaly Detection and Localization Using GAN and One-Class Classifier홍배 김
 
Introduction to Machine Learning with Python and scikit-learn
Introduction to Machine Learning with Python and scikit-learnIntroduction to Machine Learning with Python and scikit-learn
Introduction to Machine Learning with Python and scikit-learnMatt Hagy
 
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...A SVM Applied Text Categorization of Academia-Industry Collaborative Research...
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...National Institute of Informatics
 
Comparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for RegressionComparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for RegressionSeonho Park
 
XGBoost: the algorithm that wins every competition
XGBoost: the algorithm that wins every competitionXGBoost: the algorithm that wins every competition
XGBoost: the algorithm that wins every competitionJaroslaw Szymczak
 
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
From Java Code to Java Heap: Understanding the Memory Usage of Your App  - Ch...From Java Code to Java Heap: Understanding the Memory Usage of Your App  - Ch...
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...jaxLondonConference
 
Network Metrics and Measurements in the Era of the Digital Economies
Network Metrics and Measurements in the Era of the Digital EconomiesNetwork Metrics and Measurements in the Era of the Digital Economies
Network Metrics and Measurements in the Era of the Digital EconomiesPavel Loskot
 

What's hot (20)

Introduction to deep learning using python
Introduction to deep learning using pythonIntroduction to deep learning using python
Introduction to deep learning using python
 
unsplitted slideshare
unsplitted slideshareunsplitted slideshare
unsplitted slideshare
 
机器学习Adaboost
机器学习Adaboost机器学习Adaboost
机器学习Adaboost
 
Python for Computer Vision - Revision
Python for Computer Vision - RevisionPython for Computer Vision - Revision
Python for Computer Vision - Revision
 
Session 06 machine learning.pptx
Session 06 machine learning.pptxSession 06 machine learning.pptx
Session 06 machine learning.pptx
 
Software tookits for machine learning and graphical models
Software tookits for machine learning and graphical modelsSoftware tookits for machine learning and graphical models
Software tookits for machine learning and graphical models
 
Java7 Garbage Collector G1
Java7 Garbage Collector G1Java7 Garbage Collector G1
Java7 Garbage Collector G1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Generative adversarial networks
Generative adversarial networksGenerative adversarial networks
Generative adversarial networks
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
 
08 ds and algorithm session_11
08 ds and algorithm session_1108 ds and algorithm session_11
08 ds and algorithm session_11
 
Anomaly Detection and Localization Using GAN and One-Class Classifier
Anomaly Detection and Localization  Using GAN and One-Class ClassifierAnomaly Detection and Localization  Using GAN and One-Class Classifier
Anomaly Detection and Localization Using GAN and One-Class Classifier
 
Introduction to Machine Learning with Python and scikit-learn
Introduction to Machine Learning with Python and scikit-learnIntroduction to Machine Learning with Python and scikit-learn
Introduction to Machine Learning with Python and scikit-learn
 
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...A SVM Applied Text Categorization of Academia-Industry Collaborative Research...
A SVM Applied Text Categorization of Academia-Industry Collaborative Research...
 
Comparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for RegressionComparison Study of Decision Tree Ensembles for Regression
Comparison Study of Decision Tree Ensembles for Regression
 
XGBoost: the algorithm that wins every competition
XGBoost: the algorithm that wins every competitionXGBoost: the algorithm that wins every competition
XGBoost: the algorithm that wins every competition
 
Machine learning
Machine learningMachine learning
Machine learning
 
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
From Java Code to Java Heap: Understanding the Memory Usage of Your App  - Ch...From Java Code to Java Heap: Understanding the Memory Usage of Your App  - Ch...
From Java Code to Java Heap: Understanding the Memory Usage of Your App - Ch...
 
Network Metrics and Measurements in the Era of the Digital Economies
Network Metrics and Measurements in the Era of the Digital EconomiesNetwork Metrics and Measurements in the Era of the Digital Economies
Network Metrics and Measurements in the Era of the Digital Economies
 

Similar to London useR Meeting 21-Jul-09

Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonRalf Gommers
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Gabriel Moreira
 
Simple APIs and innovative documentation
Simple APIs and innovative documentationSimple APIs and innovative documentation
Simple APIs and innovative documentationPyDataParis
 
Feature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive modelsFeature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive modelsGabriel Moreira
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
 
The Heatmap
 - Why is Security Visualization so Hard?
The Heatmap
 - Why is Security Visualization so Hard?The Heatmap
 - Why is Security Visualization so Hard?
The Heatmap
 - Why is Security Visualization so Hard?Raffael Marty
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsRajendran
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptxkarthikks82
 
EDA tools and making sense of data.pdf
EDA tools and making sense of   data.pdfEDA tools and making sense of   data.pdf
EDA tools and making sense of data.pdf9wldv5h8n
 
Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2yannabraham
 
Human Activity Recognition
Human Activity RecognitionHuman Activity Recognition
Human Activity RecognitionAshwinGill1
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxAkashgupta517936
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...HendraPurnama31
 
Cheat sheets for AI
Cheat sheets for AICheat sheets for AI
Cheat sheets for AINcib Lotfi
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)Stefan Urbanek
 
ML Basic Concepts.pdf
ML Basic Concepts.pdfML Basic Concepts.pdf
ML Basic Concepts.pdfManishaS49
 

Similar to London useR Meeting 21-Jul-09 (20)

Standardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for PythonStandardizing on a single N-dimensional array API for Python
Standardizing on a single N-dimensional array API for Python
 
Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017Feature Engineering - Getting most out of data for predictive models - TDC 2017
Feature Engineering - Getting most out of data for predictive models - TDC 2017
 
Simple APIs and innovative documentation
Simple APIs and innovative documentationSimple APIs and innovative documentation
Simple APIs and innovative documentation
 
Numpy Talk at SIAM
Numpy Talk at SIAMNumpy Talk at SIAM
Numpy Talk at SIAM
 
Feature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive modelsFeature Engineering - Getting most out of data for predictive models
Feature Engineering - Getting most out of data for predictive models
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
The Heatmap
 - Why is Security Visualization so Hard?
The Heatmap
 - Why is Security Visualization so Hard?The Heatmap
 - Why is Security Visualization so Hard?
The Heatmap
 - Why is Security Visualization so Hard?
 
Basic terminologies & asymptotic notations
Basic terminologies & asymptotic notationsBasic terminologies & asymptotic notations
Basic terminologies & asymptotic notations
 
Introduction to R.pptx
Introduction to R.pptxIntroduction to R.pptx
Introduction to R.pptx
 
EDA tools and making sense of data.pdf
EDA tools and making sense of   data.pdfEDA tools and making sense of   data.pdf
EDA tools and making sense of data.pdf
 
Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2Elegant Graphics for Data Analysis with ggplot2
Elegant Graphics for Data Analysis with ggplot2
 
Human Activity Recognition
Human Activity RecognitionHuman Activity Recognition
Human Activity Recognition
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
 
Decision Tree.pptx
Decision Tree.pptxDecision Tree.pptx
Decision Tree.pptx
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 
Cheat sheets for AI
Cheat sheets for AICheat sheets for AI
Cheat sheets for AI
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)Python business intelligence (PyData 2012 talk)
Python business intelligence (PyData 2012 talk)
 
ML Basic Concepts.pdf
ML Basic Concepts.pdfML Basic Concepts.pdf
ML Basic Concepts.pdf
 

London useR Meeting 21-Jul-09

  • 1. Developing S4 Classes for Medical Imaging Data Initial Experience(s) Brandon Whitcher, PhD GlaxoSmithKline Clinical Imaging Centre
  • 2. Acknowledgements • S4 Classes and Methods – Slides by F. Leisch and P. Murrell – Software for Data Analysis by J. Chambers – R Programming for Bioinformatics by R. Gentlemen – R packages • nlme • kernlab • EBImage 2
  • 3. OOP and Classes in R • One identifies real objects, and the operations on them, that are interesting. – These operations can be systematically implemented. • A basic principle (hope) is that by faithfully representing the objects we get easier-to-implement functions. • A class is an abstract definition of a concrete real-world object. • A class system is a software infrastructure that is designed to help construct classes and to provide programmatic support for dealing with classes. 3
  • 4. Why (S4) Classes for Medical Imaging Data? • Context of imaging data • Interface with data standards and third-party software • Numerous processing steps involved – Multiple information sources • Audit trail (internal and external agencies) • Too easy to make mistakes! 4
  • 5. Data Analysis Pipeline Test statistics Motion correction Model building p-values Warping Parameter Multiple Co-registration estimation comparisons Data Mathematical Statistical Pre-processing Modelling Analysis Results 5
  • 6. Medical Imaging Data Slice Thickness; e.g. 5mm Z Y X X Chosen parameters depend Spatial Resolution on many factors: application, Size = X × Y; e.g. 256×256 scanner, local practice, radiologist preferences, etc. e.g. 0.4mm 6
  • 7. Composition of Structural Data NIfTI 3D convert Z X Y 7 DICOM
  • 8. Composition of Dynamic Data ••• ••• Z Z NIfTI 4D X X Y Y t=1 ••• t=T 8
  • 9. The nifti Class • Inherits from class array • Contains 44 “slots” (not counting .Data) – both numeric and character strings [348 bytes] setClass(“nifti”, representation(“sizeof_hdr”=“numeric”, “data_type”=“character”, ...), prototype(“sizeof_hdr”=348, “data_type”=“”, ...), contains=“array”) • Also created function nifti() for user-defined slots. • Similar class has been defined for ANALYZE data. 9
  • 10. Method “show” for nifti Class setMethod(“show”, “nifti”, function(object) { cat(“NIfTI-1 file format”, fill=TRUE) cat(...) cat(...) }) > ffd NIfTI-1 format Type : nifti Data Type : 4 (INT16) Bits per Pixel : 16 Slice Code : 0 (Unknown) Intent Code : 0 (None) Qform Code : 1 (Scanner_Anat) Sform Code : 0 (Unknown) Dimension : 64 x 64 x 21 x 180 Pixel Dimension : 4 x 4 x 6 x 3 Voxel Units : mm Time Units : sec 10
  • 11. Validity Checking for nifti Class setValidity(“nifti”, function(object) { retval <- NULL ... if (object@”sizeof_hdr” != 348) retval <- c(retval, “sizeof_hdr != 348”) if (!object@datatype %in% c(2^(1:11),768,1280,1536,1792)) retval <- c(retval, “datatype not recognized”) ... if (!all(object@”dim_”[indices] == dim(object@.Data))) retval <- c(retval, “dim/img mismatch”) ... if (is.null(retval)) return(TRUE) else return(retval) }) 11
  • 12. Manipulation of Slots • The nifti header allows limited text information – descrip (80 characters) and aux_file (24 characters) Slots Acessor functions > mniLR@”aux_file” > aux.file(mniLR) [1] "none " [1] "none " > mni@”descrip” > descrip(mniLR) [1] "FSL3.2beta" [1] "FSL3.2beta" – Replacement functions setMethod(“descrip”, “nifti”, function(object) { object@descrip }) setGeneric(“descrip<-”, function(x, value) { standardGeneric(“descrip<-”) }) setReplaceMethod(“descrip”, “nifti”, function(x, value) { x@descrip <- value x }) 12
  • 13. Additional Methods • readNIfTI() and writeNIfTI() – IO functions for NIfTI data (100% R) – Affine transformations • image() – Forces S3 method into proper generic method – Equivalent to a “lightbox” representation • overlay() – Essentially, the image function for two input arrays • orthographic() – 2×2 matrix of plots: coronal, sagittal, axial – Utilizes “pixel dimension” slot 13
  • 14. ffd <- readNIfTI(“filtered_func_data.nii.gz”) image(ffd, zlim=range(ffd)) # Figure 1 zstat1 <- readNIfti(“zstat1.nii.gz”) overlay(ffd, ifelse(abs(zstat1) > 5, zstat1, NA), zlim.x=range(ffd)) # Figure 2 14
  • 15. mni <- readNIfTI(“avg152T1_LT_nifti.nii.gz”) orthographic(mni, zlim=range(mni)) > mniLR NIfTI-1 format Type : nifti Data Type : 2 (UINT8) Bits per Pixel : 8 Slice Code : 0 (Unknown) Intent Code : 0 (None) Qform Code : 0 (Unknown) Sform Code : 4 (MNI_152) Dimension : 91 x 109 x 91 Pixel Dimension : 2 x 2 x 2 Voxel Units : mm Time Units : sec 15
  • 16. Coercion and Extensions • Coercion – Implicit since nifti class is built on the array class. > A <- array(1:8^3, rep(8,3)) > B <- as(A, “nifti”) > dim(B) [1] 8 8 8 > B@”dim_” [1] 0 0 0 0 0 0 0 0 – But... it will fail validObject(). • Allow extensions via the NIfTI-1.1 mechanism. – Define new class “niftiExtension” – Implement full audit trail • XML document – library(“XML”) 16
  • 17. Conclusions • S4 classes are powerful – Robust framework – Generics and methods – Validity checking – Inheritance • ... and difficult – Documentation (lack thereof) – Examples (lack thereof) – Slower than S3 (?) 17
  • 18. Todo List • Integrate S4 class into image analysis functions. – Modification of .Data causes modification of slot(s) • Use cniftilib to be 100% NIfTI compliant – Rniftilib by Oliver Granert <o.granert@neurologie.uni-kiel.de> • Medical_Imaging task view – Seven packages in current version. 18