Binarize values to 0 and 1 based on a minimal value. For matrices, the default threshold is 0. For rasters, the default is a value determined through sampled (5e5 pixels) otsu.

Value

binarizeThreshParam

params

thresholdnumeric (optional) Values above or equal to the threshold will be set to 1. Below will be set to 0. If not provided, defaults to 0 for matrices and a value determined by otsu for rasters.
drop0logical (only for dgCMatrix, default = FALSE) Whether to run Matrix::drop0 after binarization

See also

process_param

Other threshold parameters: threshold_minmax

Examples

e <- GiottoData::loadSubObjectMini("exprObj")
# also works with matrix classes
bin_e <- processData(e, thresholdParam("binarize"))
force(bin_e)
#> An object of class exprObj : "custom"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#> 337 x 462 sparse Matrix of class "dgCMatrix"
#>                                        
#> Mlc1   . . . . . . 1 . . 1 . . . ......
#> Gprc5b . 1 . 1 . . 1 . 1 1 . 1 . ......
#> Gfap   1 . 1 1 . . 1 . 1 1 . . . ......
#> 
#>  ........suppressing 449 columns and 331 rows 
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 

gimg <- GiottoData::loadSubObjectMini("giottoLargeImage")
# also works with SpatRasters
bin_img <- processData(gimg, thresholdParam("binarize"))
plot(bin_img)