Python implementation of minimizing the mumford-shah functional for piecewise smooth image approximation.
import cv2
from AmbrosioTortorelliMinimizer import *
Use it on a grayscale image:
img = cv2.imread("image.jpg", 0)
solver = AmbrosioTortorelliMinimizer(img)
img, edges = solver.minimize()
Or on a color image:
img = cv2.imread("image.jpg", 1)
result, edges = [], []
for c in cv2.split(img):
solver = AmbrosioTortorelliMinimizer(c, alpha = 1000, beta = 0.01,
epsilon = 0.01)
f, v = solver.minimize()
result.append(f)
edges.append(v)
img = cv2.merge(result)
edges = np.maximum(*edges)
License: Use this for whatever you want.