"This notebook goes through an example of how to use DenseCRFs on non-RGB data.\n",
"At the same time, it will explain basic concepts and walk through an example, so it could be useful even if you're dealing with RGB data, though do have a look at [PyDenseCRF's README](https://github.com/lucasb-eyer/pydensecrf#pydensecrf) too!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic setup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is highly recommended you install PyDenseCRF through pip, for example `pip install git+https://github.com/lucasb-eyer/pydensecrf.git`, but if for some reason you couldn't, you can always use it like so after compiling it:"
"The unary potential consists of per-pixel class-probabilities. This could come from any kind of model such as a random-forest or the softmax of a deep neural network."
"plt.imshow(map_soln_unary); plt.axis('off'); plt.title('MAP Solution without pairwise terms');"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pairwise terms"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The whole point of DenseCRFs is to use some form of content to smooth out predictions. This is done via \"pairwise\" terms, which encode relationships between elements."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add (non-RGB) pairwise term"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For example, in image processing, a popular pairwise relationship is the \"bilateral\" one, which roughly says that pixels with either a similar color or a similar location are likely to belong to the same class."