Labels connected (connected sets) objects in a binary image.
Usage
bwlabel(x)
Arguments
x
An Image object or an array. x is considered as
a binary image, whose pixels of value 0 are considered as background
ones and other pixels as foreground ones.
Details
All pixels for each connected set of foreground (non-zero) pixels
in x are set to an unique increasing integer, starting from 1.
Hence, max(x) gives the number of connected objects in x.
Value
A GrayscaleImage object or an array, containing the
labelled version of x.
## simple example
x = readImage(system.file('images', 'shapes.png', package='EBImage'))
x = x[110:512,1:130]
display(x, title='Binary')
y = bwlabel(x)
display(normalize(y), title='Segmented')
## read nuclei images
x = readImage(system.file('images', 'nuclei.tif', package='EBImage'))
display(x)
## computes binary mask
y = thresh(x, 10, 10, 0.05)
y = opening(y, makeBrush(5, shape='disc'))
display(y, title='Cell nuclei binary mask')
## bwlabel
z = bwlabel(y)
display(normalize(z), title='Cell nuclei')
nbnuclei = apply(z, 3, max)
cat('Number of nuclei=', paste(nbnuclei, collapse=','),'\n')
## recolor nuclei in colors
cols = c('black', sample(rainbow(max(z))))
zrainbow = Image(cols[1+z], dim=dim(z))
display(zrainbow, title='Cell nuclei (recolored)')
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(EBImage)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/EBImage/bwlabel.Rd_%03d_medium.png", width=480, height=480)
> ### Name: bwlabel
> ### Title: Binary segmentation
> ### Aliases: bwlabel
>
> ### ** Examples
>
> ## simple example
> x = readImage(system.file('images', 'shapes.png', package='EBImage'))
> x = x[110:512,1:130]
> display(x, title='Binary')
> y = bwlabel(x)
> display(normalize(y), title='Segmented')
>
> ## read nuclei images
> x = readImage(system.file('images', 'nuclei.tif', package='EBImage'))
> display(x)
Only the first frame of the image stack is displayed.
To display all frames use 'all = TRUE'.
>
> ## computes binary mask
> y = thresh(x, 10, 10, 0.05)
> y = opening(y, makeBrush(5, shape='disc'))
> display(y, title='Cell nuclei binary mask')
Only the first frame of the image stack is displayed.
To display all frames use 'all = TRUE'.
>
> ## bwlabel
> z = bwlabel(y)
> display(normalize(z), title='Cell nuclei')
Only the first frame of the image stack is displayed.
To display all frames use 'all = TRUE'.
> nbnuclei = apply(z, 3, max)
> cat('Number of nuclei=', paste(nbnuclei, collapse=','),'\n')
Number of nuclei= 76,86,94,89
>
> ## recolor nuclei in colors
> cols = c('black', sample(rainbow(max(z))))
> zrainbow = Image(cols[1+z], dim=dim(z))
> display(zrainbow, title='Cell nuclei (recolored)')
>
>
>
>
>
> dev.off()
null device
1
>