Computer Vision News - July 2018
The Edge class has three functions: constructor , connect and prob . The constructor initiates the cost (weight) of the edge, the connect method forms the graph by defining the vertices of the given edge, the prob defines the constraint to be optimized using the CVXPY Problem function. Finally, after the entire graph has been constructed, the following code defines the global optimization constraint for finding the shortest path, i.e. minimizing the sum of weights passed through between source and sink. Image in-painting: The goal of image in-painting is to reconstruct a corrupted image. We will represent the reconstructed image as U with size [ m x n ]. The corrupted pixels of U are defined by the index matrix ( corr_index ). The reconstruction U is found by minimizing the total variation of U, subject to matching uncorrupted pixel values. We will use the L2 total variation, defined as: 5 Tool Computer Vision News CVXPY and Colaboratory class Vertex(object): def __init__(self, cost): self.source = Variable() self.cost = cost(self.source) self.edge_flows = [] def prob(self): net_flow = sum(self.edge_flows) + self.source return Problem(Minimize(self.cost), [net_flow == 0]) class Edge(object): def __init__(self, cost): self.flow = Variable() self.cost = cost(self.flow) def connect(self, in_vertex, out_vertex): in_vertex.edge_flows.append(-self.flow) out_vertex.edge_flows.append(self.flow) def prob(self): return Problem(Minimize(self.cost)) prob = sum([object.prob() for object in vertices + edges]) prob.solve()
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=