Movatterモバイル変換


[0]ホーム

URL:


mrf2d

Travis build statusCodecov test coverageCRAN statusLifecycle: stable

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

drawing

The goal ofmrf2d is to provide a framework for theanalysis of Markov Random Fields with pairwise interactions on2-dimensional lattices, including Hidden Markov Random Fields. Itintroduces the S4 classmrfi to describe interactionstructures in a very general way, being able to adapt from very simplecases like the Ising Model to complex anisotropic models with differenttypes of interaction.

A complete paper describing the details of the package and examplesis published in the Journal of Statistical Software and can be foundhere.


Installation

You can install the stable version ofmrf2d fromCRAN with:

install.packages("mrf2d")

The development version is available on the package’sGithub page. It can beinstalled with thedevtools package by using

devtools::install_github("Freguglia/mrf2d")

Usage

mrf2d introduces a programming interface for the generalMarkov Random Field model inFreguglia, Victor, Nancy L. Garcia, andJuliano L. Bicas. “Hidden Markov random field models applied to colorhomogeneity evaluation in dyed textile images.” Environmetrics (2019):e2613. Using specific interaction structures and parameterrestrictions can lead to important models as particular cases, such asthe Potts model.

It introduces the S4 classmrfi to represent interactionstructures. Themrfi() function can be used to create theseobjects representing interaction structures with relative positionsincluded based on the norm of the relative position (distance) orexplicitly specified

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

Potentials (parameters) are represented by three-dimensional arrays,where rows and columns represent pixel label values and slices representinteracting 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 lesslikely in that relative position.

The package has many built-in functions for sampling, potentialsestimation and hidden MRF model fitting (used for image segmentation),but it also provides all the basic stack of computations used toimplement algorithms for MRF models, making it suitable for developmentof 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, pleasefile anissue.Contributions can be done in form of code optimization, new ideas,discussing new structures, etc.


[8]ページ先頭

©2009-2025 Movatter.jp