MyNixOS website logo
Description

Markov Random Field Models for Image Analysis.

Model fitting, sampling and visualization for the (Hidden) Markov Random Field model with pairwise interactions and general interaction structure from Freguglia, Garcia & Bicas (2020) <doi:10.1002/env.2613>, which has many popular models used in 2-dimensional lattices as particular cases, like the Ising Model and Potts Model. A complete manuscript describing the package is available in Freguglia & Garcia (2022) <doi:10.18637/jss.v101.i08>.

mrf2d

Travis buildstatus Codecov testcoverage CRANstatus Lifecycle:stable

Markov Random Fields are probabilistic models capable of describing sets of random variables with a local dependence property (the Markov property) defined on a neighborhood system. Particularly on the context of image processing, pixels can be seen as vertices of a graph defined on a finite 2-dimensional lattice, and a neighborhood system can be defined based on their relative positions to construct a MRF.

drawing

The goal of mrf2d is to provide a framework for the analysis of Markov Random Fields with pairwise interactions on 2-dimensional lattices, including Hidden Markov Random Fields. It introduces the S4 class mrfi to describe interaction structures in a very general way, being able to adapt from very simple cases like the Ising Model to complex anisotropic models with different types of interaction.

A complete paper describing the details of the package and examples is published in the Journal of Statistical Software and can be found here.


Installation

You can install the stable version of mrf2d from CRAN with:

install.packages("mrf2d")

The development version is available on the package’s Github page. It can be installed with the devtools package by using

devtools::install_github("Freguglia/mrf2d")

Usage

mrf2d introduces a programming interface for the general Markov Random Field model in Freguglia, Victor, Nancy L. Garcia, and Juliano L. Bicas. “Hidden Markov random field models applied to color homogeneity evaluation in dyed textile images.” Environmetrics (2019): e2613. Using specific interaction structures and parameter restrictions can lead to important models as particular cases, such as the Potts model.

It introduces the S4 class mrfi to represent interaction structures. The mrfi() function can be used to create these objects representing interaction structures with relative positions included based on the norm of the relative position (distance) or explicitly specified

interact <- mrfi(max_norm = 1, positions = list(c(4,2)))
interact
#> 3 interacting positions.
#>   rx     ry
#>    1      0
#>    0      1
#>    4      2
plot(interact)

Potentials (parameters) are represented by three-dimensional arrays, where rows and columns represent pixel label values and slices represent interacting positions.

potentials <- expand_array(c(-0.9, -0.9, 0.2), family = "oneeach", C = 1, mrfi = interact)
potentials
#> , , (1,0)
#> 
#>      0    1
#> 0  0.0 -0.9
#> 1 -0.9  0.0
#> 
#> , , (0,1)
#> 
#>      0    1
#> 0  0.0 -0.9
#> 1 -0.9  0.0
#> 
#> , , (4,2)
#> 
#>     0   1
#> 0 0.0 0.2
#> 1 0.2 0.0

The negative values out of diagonal means different “colors” are less likely in that relative position.

The package has many built-in functions for sampling, potentials estimation and hidden MRF model fitting (used for image segmentation), but it also provides all the basic stack of computations used to implement algorithms for MRF models, making it suitable for development of research in Markov Random Field models.

set.seed(1)
img_dim <- c(200,200)
Z <- rmrf2d(img_dim, mrfi = interact, theta = potentials, cycles = 60)
dplot(Z, legend = TRUE)

Contributing and Bug Reports

If you’re interested in contributing or found a bug or error, please file an issue. Contributions can be done in form of code optimization, new ideas, discussing new structures, etc.

Metadata

Version

1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows