bwlabel               package:EBImage               R Documentation

_B_i_n_a_r_y _s_e_g_m_e_n_t_a_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Labels connected (connected sets) objects in a binary image.

_U_s_a_g_e:

       bwlabel(x)

_A_r_g_u_m_e_n_t_s:

       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.

_D_e_t_a_i_l_s:

     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'.

_V_a_l_u_e:

     An 'Grayscale' 'Image' object or an array, containing the labelled
     version of 'x'.

_A_u_t_h_o_r(_s):

     Gregoire Pau, 2009

_E_x_a_m_p_l_e_s:

       ## simple example
       x = readImage(system.file('images', 'shapes.png', package='EBImage'))
       x = x[110:512,1:130]
       if (interactive()) display(x, title='Binary')
       y = bwlabel(x)
       if (interactive()) display(normalize(y), title='Segmented')

       ## read nuclei images
       x = readImage(system.file('images', 'nuclei.tif', package='EBImage'))
       if (interactive()) display(x)

       ## computes binary mask
       y = thresh(x, 10, 10, 0.05)
       y = opening(y, makeBrush(5, shape='disc'))
       if (interactive()) display(y, title='Cell nuclei binary mask')

       ## bwlabel
       z = bwlabel(y)
       if (interactive()) 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))
       if (interactive()) display(zrainbow, title='Cell nuclei (recolored)')

