ANTsX / ANTsRCore

Rcpp bindings for the C++ ANTs library used by the ANTsR package
9 stars 9 forks source link

ThresholdImage not good with unsigned chars. #85

Closed muschellij2 closed 5 years ago

muschellij2 commented 5 years ago

Describe the bug labelClusters doesn't perform well on unsigned chars. This is really a bug in thresholdImage:

library(ANTsRCore)
#> 
#> Attaching package: 'ANTsRCore'
#> The following object is masked from 'package:stats':
#> 
#>     var
#> The following objects are masked from 'package:base':
#> 
#>     all, any, apply, max, min, prod, range, sum
minThresh = 1e-06
maxThresh = 1
fullyConnected = FALSE
imagein<-makeImage( c(40,10,10 ) , rnorm(40*10*10))
imagein = check_ants(imagein)
dim <- imagein@dimension
clust <- thresholdImage(imagein > 1, minThresh, 0.99)
sum(clust)
#> [1] 0
clust <- thresholdImage(antsImageClone(imagein > 1,
                                       out_pixeltype = "float"), 
                        minThresh, maxThresh)
sum(clust)
#> [1] 620
sum(imagein > 0)
#> [1] 2034
cc = labelClusters(imagein > 0)
sum(cc)
#> [1] 0
cc
#> antsImage
#>   Pixel Type          : unsigned char 
#>   Components Per Pixel: 1 
#>   Dimensions          : 40x10x10 
#>   Voxel Spacing       : 1x1x1 
#>   Origin              : 0 0 0 
#>   Direction           : 1 0 0 0 1 0 0 0 1
cc2 = labelClusters(antsImageClone(imagein > 0, out_pixeltype = "float"))
sum(cc2)
#> [1] 1964
cc2
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 1 
#>   Dimensions          : 40x10x10 
#>   Voxel Spacing       : 1x1x1 
#>   Origin              : 0 0 0 
#>   Direction           : 1 0 0 0 1 0 0 0 1

Created on 2019-06-06 by the reprex package (v0.2.1)