Use Gibbs sampling and variational inference to denoise the image and use EM to segment the image
python 3-6
scipy
cv2
where the ๐๐๐(๐) means all connected nodes (neighbors) of node ๐ฅ๐. Due to use the Ising model, the pairwise potential term ๐นs๐ (๐ฅ๐, ๐ฅs)=exp(๐ฝ๐ฅ๐๐ฅs), and the local evidence term ๐น๐(๐ฅ๐)=๐ฉ(๐ฆ๐|๐ฅ๐, ๐^2) where the ๐ฆ๐ is the observed state.
So the final term of p in the pseudo-code is:
And the ๐๐๐ฅ๐ก๐๐๐ก๐(๐) function can just return j. But this may cause artifacts as the pixels left and above of ๐ฅ๐ will change before it does, while the pixels right and below will not have changed. Instead, first pass over all of the "even" pixels (i is even) and then make a pass over all of the "odd" pixels will help a lot, which can also simplify the iterations into two matrix operations(instead of n times iterations).
And when meet the boundary pixels, can try to "wrap" the boundary to deal with this problem, which means that the neighbors wrap around to the other side of the image.
where the ๐๐๐(๐) means all connected nodes (neighbors) of node ๐ฅ๐. ๐๐ is mean value of node i. And the main update rule is:
Based on the ๐, it will be iterated until convergence.
The ๐๐๐ฅ๐ก๐๐๐ก๐(๐) function and boundary problem are the same as the Gibbs sampling algorithm.