Package 'findblobs'

Title: R Package to Find Connected Cells (Blobs) in a Matrix of Logical
Description: This package provides functions to find blobs of connected cells in a matrix of logical. This is also known as Blob Colouring.
Authors: Hauke Sonnenberg [aut, cre]
Maintainer: Hauke Sonnenberg <[email protected]>
License: MIT
Version: 0.0.0.9000
Built: 2024-11-14 02:41:55 UTC
Source: https://github.com/hsonne/findblobs

Help Index


Find Connected Cells along Matrix Columns

Description

Find Connected Cells along Matrix Columns

Usage

get_column_blobs(m, offset = 0L)

Arguments

m

a matrix of logical

offset

integer to be added to the numbers indicating connected cells

Value

matrix of integer having the same dimension as m. Cells being FALSE in m are 0 in the output. Cells being TRUE in m are a positive integer number in the output. Connected cells within same columns share the same number.

Examples

column_blobs <- findblobs:::get_column_blobs(
  matrix(ncol = 3, byrow = TRUE, c(
    FALSE, TRUE, FALSE,
    TRUE,  TRUE, FALSE,
    FALSE, FALSE, TRUE,
    TRUE,  TRUE,  TRUE,
    TRUE,  FALSE, TRUE
  ))
)

findblobs::plot_integer_matrix(column_blobs)

Order List of Vectors by First Vector Elements

Description

Order List of Vectors by First Vector Elements

Usage

order_by_first(x)

Arguments

x

list of vectors

Examples

findblobs:::order_by_first(list(
  c(3, 4),
  c(1, 5, 6),
  c(2, 1)
))

Create Random Blobs in a Matrix

Description

Create Random Blobs in a Matrix

Usage

place_random_blobs(
  m = matrix(0L, nrow = 10, ncol = 15),
  n_blobs = 5,
  min_fields = 3,
  max_fields = min_fields,
  do_plot = TRUE
)

Arguments

m

matrix of integer in which to place blobs. Default: 10 x 15-Matrix

n_blobs

number of blobs to create. Default: 5

min_fields

minimum number of fields a blob should consist of

max_fields

maximum number of fields a blob should consist of. Defaults to min_fields

do_plot

if TRUE (the default), the result matrix is plotted

Value

matrix in which fields belonging to the same blob have the same integer number and zeros indicate empty fields

Examples

set.seed(42)
place_random_blobs(n_blobs = 5, min_fields = 5, max_fields = 10)

Plot Matrix of Integer as Coloured Squares

Description

Plot Matrix of Integer as Coloured Squares

Usage

plot_integer_matrix(x, colours = NULL)

Arguments

x

matrix of integer

Examples

plot_integer_matrix(matrix(nrow = 5, byrow = TRUE, c(
  2, 2, 2, 2, 2,
  2, 0, 1, 0, 2,
  2, 1, 1, 1, 2,
  2, 0, 1, 0, 2,
  2, 2, 2, 2, 2
)))

Create Matrix with Randomly "Filled" Fields

Description

Create Matrix with Randomly "Filled" Fields

Usage

random_matrix(matrix_dim = c(10, 10))

Arguments

matrix_dim

numeric vector of length two giving the number of rows and columns, respectively of the matrix