The code provided in connection with the section 5.2 (MRF modelling for image segmentation) of the lecture notes.
The code provided in connection with the section 5.2 (MRF modelling for image segmentation) of the lecture notes.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
importskimage.io
importskimage.io
importnumpyasnp
importnumpyasnp
importscipy.ndimage
importscipy.ndimage
importmatplotlib.pyplotasplt
importmatplotlib.pyplotasplt
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
You should write the code which computes segmentation energies (U1 and U2) as described in the lecture notes. The skeleton of the function is provided below.
You should write the code which computes segmentation energies (U1 and U2) as described in the lecture notes. The skeleton of the function is provided below.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
defsegmentation_energy(S,D,mu,beta):
defsegmentation_energy(S,D,mu,beta):
# TODO -- add your code here
# TODO -- add your code here
# likelihood energy
# likelihood energy
U1=0
U1=0
# prior energy
# prior energy
U2=0
U2=0
returnU1,U2
returnU1,U2
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
A helping function for plotting the histograms of the data and the segmentation.
A helping function for plotting the histograms of the data and the segmentation.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
defsegmentation_histogram(ax,D,S,edges=None):
defsegmentation_histogram(ax,D,S,edges=None):
'''
'''
Plot histogram for grayscale data and each segmentation label.
Plot histogram for grayscale data and each segmentation label.
Visualize the segmentations, associated histograms and error images. Once you implement the `segmentation_energy` you can look at whether there is a link between segmentation energies and the quality of the segmentation.
Visualize the segmentations, associated histograms and error images. Once you implement the `segmentation_energy` you can look at whether there is a link between segmentation energies and the quality of the segmentation.