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 |
Find Connected Cells along Matrix Columns
get_column_blobs(m, offset = 0L)
get_column_blobs(m, offset = 0L)
m |
a matrix of logical |
offset |
integer to be added to the numbers indicating connected cells |
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.
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)
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
order_by_first(x)
order_by_first(x)
x |
list of vectors |
findblobs:::order_by_first(list( c(3, 4), c(1, 5, 6), c(2, 1) ))
findblobs:::order_by_first(list( c(3, 4), c(1, 5, 6), c(2, 1) ))
Create Random Blobs in a Matrix
place_random_blobs( m = matrix(0L, nrow = 10, ncol = 15), n_blobs = 5, min_fields = 3, max_fields = min_fields, do_plot = TRUE )
place_random_blobs( m = matrix(0L, nrow = 10, ncol = 15), n_blobs = 5, min_fields = 3, max_fields = min_fields, do_plot = TRUE )
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 |
do_plot |
if |
matrix in which fields belonging to the same blob have the same integer number and zeros indicate empty fields
set.seed(42) place_random_blobs(n_blobs = 5, min_fields = 5, max_fields = 10)
set.seed(42) place_random_blobs(n_blobs = 5, min_fields = 5, max_fields = 10)
Plot Matrix of Integer as Coloured Squares
plot_integer_matrix(x, colours = NULL)
plot_integer_matrix(x, colours = NULL)
x |
matrix of integer |
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 )))
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
random_matrix(matrix_dim = c(10, 10))
random_matrix(matrix_dim = c(10, 10))
matrix_dim |
numeric vector of length two giving the number of rows and columns, respectively of the matrix |