I was trying to extract the hair from a given image as described in the research paper, using the concept of energy minimisation, The energy function is dependent on both Prior probability and YCrCb colour likelihood histogram. The energy function is defined as:
๐ธ(๐x)= ๐ธdata(๐x)+๐ธsmooth(๐x).
๐ธdata (๐x)=โโ(log๐(I(x)|๐x)+log๐sel (๐x)) [Prior probability model]
๐ธsmooth (๐x) = โ ๐ฟ(๐x =ฬธ๐x )exp(-||๐(x๐)โ๐(x๐)||^2/๐พ) [Prior YcrCb color model]
I am confused at how to label the given graph(pixels of the images are treated as nodes of graph). I tried to label the graph using the following approach but the results are not as expected:
def get_Edata(prob_dist, ycrcb_dist, img_y, img_x, pix):
e_data = 0
Y, Cr, Cb = pix
if ycrcb_dist[int(Y/4)][int(Cr/4)][int(Cb/4)] > 0 and prob_dist[img_y][img_x]>0:
e_data = -1*(math.log(ycrcb_dist[int(Y/4)][int(Cr/4)][int(Cb/4)], 10) + math.log(prob_dist[img_y][img_x], 10))
return e_data
def get_ESmooth(normalization_constant, pix_1, pix_2):
return math.exp(-(math.ceil(pix_1[0] - pix_2[0])**2)/normalization_constant)
And while adding weight between the nodes in graph I use:
#adding the edges between neighbouring pixels.
img_graph.add_edge(central_node, neighbour_nodes, eSmooth, 0)
#adding the edges from source to node and from node to sink.
img_graph.add_tedge(central_node, weight_source, max_val_weight-source)
I guess the issue is with the max_val_weight-source
because changing the value to some lower integer gives me relatively good results but that is not the right way of doing it.
Also changing the value of eSmooth to 0 doesn't affects the output?
I would highly appreciate if someone could shed some light on this context.