Implementing graph cut on image using Energy function
Asked Answered
N

0

9

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.

Nitride answered 24/7, 2015 at 2:21 Comment(1)
please format your question to be more readable / human friendly so you can get good answers. โ€“ Stricken

© 2022 - 2024 โ€” McMap. All rights reserved.