# Path: filtering/morphology.py
# def ssm(img, anisotropic=False, iterations=30):
#     '''
#     Skeleton strength map
#     img: the input image
#     anisotropic: True if using anisotropic diffusion
#     iterations: number of iterations to optimise the GVF
#     '''
#     # f = gaussian_gradient_magnitude(img, 1)
#     # f = 1 - gimg # Inverted version of the smoothed
#     # gradient of the distance transform
# 
#     gvfmap = gvf(img, mu=0.001, iterations=iterations, anisotropic=anisotropic)
# 
#     shifts = [-1, 1, -1, -1, -1, 1]
#     axis = [1, 1, 2, 2, 3, 3]
#     shiftmat = np.zeros(gvfmap.shape)
#     f = np.zeros(img.shape)  # reuse f for saving the SSM
# 
#     for i, (s, a) in enumerate(zip(shifts, axis)):
#         # Only the orthogonal neighbours
#         shiftmat.fill(0)
#         shiftmat[a - 1, :, :, :] = s
# 
#         # Dot product gvf and neighbour displacement fields /
#         # distance between neighbour
#         f += np.sum(np.roll(
#             gvfmap, s, axis=a) * shiftmat, axis=0) / np.linalg.norm(
#                 shiftmat, axis=0)
# 
#     f[np.isnan(f)] = 0
#     f[f < 0] = 0
#     return f


from filtering.morphology import ssm
from rivuletpy.utils.io import * 
    from skimage import filters
    from skimage import filter as filters
import matplotlib.pyplot as plt
import skfmm

ITER = 30

img = loadimg('/home/siqi/ncidata/rivuletpy/tests/data/test-crop.tif')
bimg = (img > 0).astype('int')
dt = skfmm.distance(bimg, dx=1)

# Path: filtering/morphology.py
# def ssm(img, anisotropic=False, iterations=30):
#     '''
#     Skeleton strength map
#     img: the input image
#     anisotropic: True if using anisotropic diffusion
#     iterations: number of iterations to optimise the GVF
#     '''
#     # f = gaussian_gradient_magnitude(img, 1)
#     # f = 1 - gimg # Inverted version of the smoothed
#     # gradient of the distance transform
# 
#     gvfmap = gvf(img, mu=0.001, iterations=iterations, anisotropic=anisotropic)
# 
#     shifts = [-1, 1, -1, -1, -1, 1]
#     axis = [1, 1, 2, 2, 3, 3]
#     shiftmat = np.zeros(gvfmap.shape)
#     f = np.zeros(img.shape)  # reuse f for saving the SSM
# 
#     for i, (s, a) in enumerate(zip(shifts, axis)):
#         # Only the orthogonal neighbours
#         shiftmat.fill(0)
#         shiftmat[a - 1, :, :, :] = s
# 
#         # Dot product gvf and neighbour displacement fields /
#         # distance between neighbour
#         f += np.sum(np.roll(
#             gvfmap, s, axis=a) * shiftmat, axis=0) / np.linalg.norm(
#                 shiftmat, axis=0)
# 
#     f[np.isnan(f)] = 0
#     f[f < 0] = 0
#     return f


# Path: tests/testssm.py
from filtering.morphology import ssm
from rivuletpy.utils.io import * 
    from skimage import filters
    from skimage import filter as filters
import matplotlib.pyplot as plt
import skfmm


ITER = 30

img = loadimg('/home/siqi/ncidata/rivuletpy/tests/data/test-crop.tif')
bimg = (img > 0).astype('int')
dt = skfmm.distance(bimg, dx=1)

sdt = ssm(dt, anisotropic=True, iterations=ITER)