I am very new with MRF
and not that much good at programming.
I have obtained probability map from semantic segmentation using a CNN, I have to optimize the segmentation by using Markov Random Fields (MRF).
I download the code provided by Shai Bagon in this link GCmex. Energy minimization is performed based on either alpha expansion or swap.
I compiled the code by mex and I need to refine the Unary and pair-wise energy minimization functions. I have a stack of images and need to extract the 6-neighborhood grid and include the refined neighboring in the pair-wise function.
The input to the Unary function is the probability map which is a stack with size (256,256,4) for 4 different classes:
My questions are: Has someone refined the code according to the defining different energy function 1) I wanna change Unary and pair-wise formulation). Which functions and which parts of code should be refined and recompiled again?
2) How to change the w_i,j
? it is calculate based on intensity difference, here we have only probabilities, Is it the difference of probabilities of two adjacent voxels?
I really appreciate your help. Thanks
You have 60 slices of
256x256
pix (tot ~4G voxels), that isslices
is a256
-by-256
-by-60
array. Once you feedslices
into your net (one by one or in batches - whatever works best for you) you haveprob
probability of size256
-by-256
-by-60
-by-4
.I suggest you use third constructor of
GCMex
to construct your graph for optimization.To do so, you first need to define a sparse graph. Use
sparse_adj_matrix
:Once you have the graph, it's all down hill from here:
To see the output labels, you need to
reshape
PS,
If your spatial distance between slices is larger than the gap between neighboring voxels in the same slice, you might need to use different
sig2
forii
andjj
that are in the same slice and forii
andjj
that are on different slices. This requires a bit of an effort.