Giter VIP home page Giter VIP logo

imbibe's Introduction

Build Status

imbibe: A pipe-friendly image calculator

The imbibe R package offers fast, chainable image-processing operations which are applicable to images of two, three or four dimensions. It provides an R interface to the core C functions of the niimath project by Chris Rorden, which is in turn a free-software reimplementation of fslmaths, so it has its roots in medical image analysis and is particularly well-suited to such data. The package was designed from the outset to work well with the pipe syntax widely popularised amongst R users by the Tidyverse family of packages.

Installation

This package is still at quite an early stage of development. The latest version can be easily installed using the remotes package.

## install.packages("remotes")
remotes::install_github("jonclayden/imbibe")

Usage

The first step for any usage of the package is to create or read in an image. We will use a 3D medical image from the RNifti package by way of an example.

library(RNifti)
library(imbibe)
image <- readNifti(system.file("extdata", "example.nii.gz", package="RNifti"))

We can also use the RNifti image viewer to visualise the image.

view(image)

plot of chunk original

A simple example operation would be to smooth the image with a Gaussian smoothing kernel of standard deviation 4 mm. We can use standard R syntax to perform this operation, return a result, and then show it:

smoothed <- run(smooth_gauss(image, 4))
view(smoothed)
## Setting window to (0, 549.9)

plot of chunk standard

Here, smooth_gauss() requests the smoothing operation, and run() actually runs the pipeline and returns the processed image.

However, the pipe syntax provides an alternative, which can be further simplified because calling view() on a pipeline will implicitly run it.

image %>% smooth_gauss(4) %>% view()
## Setting window to (0, 549.9)

plot of chunk pipe

Notice now smooth_gauss() is now called with only one argument, and view() with none, because the input to the pipe (%>%) is implicitly added first. The benefits to readability of this approach increase substantially as more operations are added to the chain:

image %>% kernel_sphere(radius=3) %>% dilate() %>% subtract(image) %>% view()
## Setting window to (0, 60)

plot of chunk dilate

This example sets up a spherical kernel of radius 3 mm, dilates the image with it, and then subtracts the original image from the result to leave just the outer edge of the imaged object.

imbibe's People

Contributors

jonclayden avatar muschellij2 avatar neurolabusc avatar ningfei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

imbibe's Issues

Found issues

drt_mean

Getting a bunch of ** nifti_set_filenames, bad params 0x0, 0x7ff62949a1d0 when trying drt functions

library(imbibe)
fname = system.file("extdata/example_4d.nii.gz", package = "RNifti")
image = RNifti::readNifti(fname)
image %>% drt_mean() %>% RNifti::view()
#> beta: Using 64-bit calc
#> Warning in run(x): nifti_image_read: failed to find header file for '#1'
#> Error in if (any(is.na(window)) || (min == max)) {: missing value where TRUE/FALSE needed
image %>% drt_mean() %>% run()
#> beta: Using 64-bit calc
#> Warning in run(.): nifti_image_read: failed to find header file for '#1'
#> NULL
fname %>% drt_mean %>% run
#> beta: Using 64-bit calc
#> Warning in run(.): nifti_image_read: failed to find header file for '#1'
#> NULL

Created on 2020-09-28 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Catalina 10.15.6      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2020-09-28                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version     date       lib source                           
#>  assertthat    0.2.1       2019-03-21 [2] CRAN (R 4.0.0)                   
#>  backports     1.1.10      2020-09-15 [1] CRAN (R 4.0.2)                   
#>  callr         3.4.4       2020-09-07 [1] CRAN (R 4.0.2)                   
#>  cli           2.0.2       2020-02-28 [2] CRAN (R 4.0.0)                   
#>  crayon        1.3.4       2017-09-16 [2] CRAN (R 4.0.0)                   
#>  desc          1.2.0       2020-06-01 [2] Github (muschellij2/desc@b0c374f)
#>  devtools      2.3.1.9000  2020-08-25 [2] Github (r-lib/devtools@df619ce)  
#>  digest        0.6.25      2020-02-23 [2] CRAN (R 4.0.0)                   
#>  ellipsis      0.3.1       2020-05-15 [2] CRAN (R 4.0.0)                   
#>  evaluate      0.14        2019-05-28 [2] CRAN (R 4.0.0)                   
#>  fansi         0.4.1       2020-01-08 [2] CRAN (R 4.0.0)                   
#>  fs            1.5.0       2020-07-31 [2] CRAN (R 4.0.2)                   
#>  glue          1.4.2       2020-08-27 [1] CRAN (R 4.0.2)                   
#>  highr         0.8         2019-03-20 [2] CRAN (R 4.0.0)                   
#>  htmltools     0.5.0       2020-06-16 [2] CRAN (R 4.0.0)                   
#>  imbibe      * 0.1.0       2020-09-28 [1] local                            
#>  knitr         1.29        2020-06-23 [2] CRAN (R 4.0.2)                   
#>  lifecycle     0.2.0       2020-03-06 [2] CRAN (R 4.0.0)                   
#>  magrittr      1.5         2014-11-22 [2] CRAN (R 4.0.0)                   
#>  memoise       1.1.0       2017-04-21 [2] CRAN (R 4.0.0)                   
#>  pkgbuild      1.1.0       2020-07-13 [2] CRAN (R 4.0.2)                   
#>  pkgload       1.1.0       2020-05-29 [2] CRAN (R 4.0.0)                   
#>  prettyunits   1.1.1       2020-01-24 [2] CRAN (R 4.0.0)                   
#>  processx      3.4.4       2020-09-03 [1] CRAN (R 4.0.2)                   
#>  ps            1.3.4       2020-08-11 [2] CRAN (R 4.0.2)                   
#>  purrr         0.3.4       2020-04-17 [2] CRAN (R 4.0.0)                   
#>  R6            2.4.1       2019-11-12 [2] CRAN (R 4.0.0)                   
#>  Rcpp          1.0.5       2020-07-06 [2] CRAN (R 4.0.0)                   
#>  remotes       2.2.0       2020-07-21 [2] CRAN (R 4.0.2)                   
#>  rlang         0.4.7.9000  2020-09-09 [1] Github (r-lib/rlang@60c0151)     
#>  rmarkdown     2.3         2020-06-18 [2] CRAN (R 4.0.0)                   
#>  RNifti        1.2.2       2020-09-07 [1] CRAN (R 4.0.2)                   
#>  rprojroot     1.3-2       2018-01-03 [2] CRAN (R 4.0.0)                   
#>  sessioninfo   1.1.1       2018-11-05 [2] CRAN (R 4.0.0)                   
#>  stringi       1.5.3       2020-09-09 [1] CRAN (R 4.0.2)                   
#>  stringr       1.4.0       2019-02-10 [2] CRAN (R 4.0.0)                   
#>  testthat      2.99.0.9000 2020-09-17 [1] Github (r-lib/testthat@fbbd667)  
#>  usethis       1.6.1.9001  2020-08-25 [2] Github (r-lib/usethis@860c1ea)   
#>  withr         2.2.0       2020-04-20 [2] CRAN (R 4.0.0)                   
#>  xfun          0.17        2020-09-09 [1] CRAN (R 4.0.2)                   
#>  yaml          2.2.1       2020-02-01 [2] CRAN (R 4.0.0)                   
#> 
#> [1] /Users/johnmuschelli/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.