Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 Channel 2D Images Fail #105

Open
muschellij2 opened this issue Nov 22, 2019 · 0 comments
Open

3 Channel 2D Images Fail #105

muschellij2 opened this issue Nov 22, 2019 · 0 comments

Comments

@muschellij2
Copy link
Collaborator

Image from https://radiopaedia.org/cases/hand-arthropathies-distribution-diagram-1

hand-arthropathies-distribution-diagram-1

Describe the bug
When you read in a 2D image with multiple channels, normal masking seems to be broken (and likely other operations).

To Reproduce

library(ANTsRCore)
#> 
#> Attaching package: 'ANTsRCore'
#> The following objects are masked from 'package:stats':
#> 
#>     sd, var
#> The following objects are masked from 'package:base':
#> 
#>     all, any, apply, max, min, prod, range, sum
url = "https://user-images.githubusercontent.com/1075118/69453677-66a77d80-0d32-11ea-80ba-c6d5bfeaae53.jpeg"
destfile = tempfile(fileext = ".jpg")
download.file(url, destfile)
img = antsImageRead(destfile)
img > 0
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 3 
#>   Dimensions          : 1024x1024 
#>   Voxel Spacing       : 1xNA 
#>   Origin              : 0 NA 
#>   Direction           : 1 0 0 1
dim(img > 0)
#> [1] 1024 1024
img[img > 0]
#> Error in img[img > 0]: Length of mask vector does not match image-region dimensions

split_img = splitChannels(img)
split_img = lapply(split_img, function(x) {
  x / 255
})
gray_img = Reduce(f = "+", split_img)
gray_img > 0
#> antsImage
#>   Pixel Type          : unsigned char 
#>   Components Per Pixel: 1 
#>   Dimensions          : 1024x1024 
#>   Voxel Spacing       : 1x1 
#>   Origin              : 0 0 
#>   Direction           : 1 0 0 1
dim(gray_img > 0)
#> [1] 1024 1024
gray_img[gray_img > 0]
#>     [1] 0.27058825 0.36470589 0.36470589 0.35294119 0.35294119 0.34117648
#>  [ reached getOption("max.print") -- omitted 594406 entries ]

Created on 2019-11-22 by the reprex package (v0.3.0.9000)

Session info
sessioninfo::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       macOS Mojave 10.14.6        
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-11-22                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version   date       lib source                            
#>  ANTsRCore   * 0.7.3     2019-11-05 [1] Github (ANTsX/ANTsRCore@f564041)  
#>  assertthat    0.2.1     2019-03-21 [1] CRAN (R 3.6.0)                    
#>  cli           1.1.0     2019-03-19 [1] CRAN (R 3.6.0)                    
#>  crayon        1.3.4     2017-09-16 [1] CRAN (R 3.6.0)                    
#>  digest        0.6.22    2019-10-21 [1] CRAN (R 3.6.0)                    
#>  evaluate      0.14      2019-05-28 [1] CRAN (R 3.6.0)                    
#>  highr         0.8       2019-03-20 [1] CRAN (R 3.6.0)                    
#>  htmltools     0.4.0     2019-10-04 [1] CRAN (R 3.6.0)                    
#>  ITKR          0.5.2     2019-11-05 [1] Github (stnava/ITKR@fe97efa)      
#>  knitr         1.24.3    2019-08-28 [1] Github (muschellij2/knitr@abcea3d)
#>  lattice       0.20-38   2018-11-04 [1] CRAN (R 3.6.0)                    
#>  magrittr      1.5       2014-11-22 [1] CRAN (R 3.6.0)                    
#>  Matrix        1.2-17    2019-03-22 [1] CRAN (R 3.6.0)                    
#>  Rcpp          1.0.3     2019-11-08 [1] CRAN (R 3.6.0)                    
#>  RcppEigen     0.3.3.5.0 2018-11-24 [1] CRAN (R 3.6.0)                    
#>  rlang         0.4.1     2019-10-24 [1] CRAN (R 3.6.0)                    
#>  rmarkdown     1.16      2019-10-01 [1] CRAN (R 3.6.0)                    
#>  sessioninfo   1.1.1     2018-11-05 [1] CRAN (R 3.6.0)                    
#>  stringi       1.4.3     2019-03-12 [1] CRAN (R 3.6.0)                    
#>  stringr       1.4.0     2019-02-10 [1] CRAN (R 3.6.0)                    
#>  withr         2.1.2     2018-03-15 [1] CRAN (R 3.6.0)                    
#>  xfun          0.11      2019-11-12 [1] CRAN (R 3.6.0)                    
#>  yaml          2.2.0     2018-07-25 [1] CRAN (R 3.6.0)                    
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

Expected behavior
2D binary image returned.

Desktop (please complete the following information):

  • OS: OSX Mojave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant