def deform_grid(self):
        for node in self.pixel_graph.nodes_iter():
            self.deform_pixel(node)

        # Collapse all valence-2 nodes.
        removals = []
        for node in self.grid_graph.nodes_iter():
            if node in ((0, 0), (0, self.size[1]),
                        (self.size[0], 0), self.size):
                # Skip corner nodes.
                continue
            neighbors = self.grid_graph.neighbors(node)
            if len(neighbors) == 2:
                self.grid_graph.add_edge(*neighbors)
            if len(neighbors) <= 2:
                removals.append(node)

        # We can't do this above, because it would modify the dict
        # we're iterating.
        for node in removals:
            self.grid_graph.remove_node(node)

        # Update pixel corner sets.
        for node, attrs in self.pixel_graph.nodes_iter(data=True):
            corners = attrs['corners']
            for corner in corners.copy():
                if corner not in self.grid_graph:
                    corners.remove(corner)
Deform the pixel grid based on the connections between similar pixels.
dataset/ETHPy150Open jerith/depixel/depixel/depixeler.py/PixelData.deform_grid