Ejemplo n.º 1
0
def test_geodesic_distance2d():
    I = np.asarray(Image.open('data/img2d.png').convert('L'), np.float32)
    S = np.zeros_like(I, np.uint8)
    S[100][100] = 1
    t0 = time.time()
    D1 = geodesic_distance.geodesic2d_fast_marching(I, S)
    t1 = time.time()
    D2 = geodesic_distance.geodesic2d_raster_scan(I, S)
    dt1 = t1 - t0
    dt2 = time.time() - t1
    print "runtime(s) of fast marching {0:}".format(dt1)
    print "runtime(s) of raster  scan  {0:}".format(dt2)
    plt.subplot(1, 3, 1)
    plt.imshow(I, cmap='gray')
    plt.autoscale(False)
    plt.plot([100], [100], 'ro')
    plt.axis('off')
    plt.title('input image')

    plt.subplot(1, 3, 2)
    plt.imshow(D1)
    plt.axis('off')
    plt.title('fast marching')

    plt.subplot(1, 3, 3)
    plt.imshow(D2)
    plt.axis('off')
    plt.title('ranster scan')
    plt.show()
Ejemplo n.º 2
0
 def process_frames(self, data):
     input_temp = data[0]
     indices = np.where(np.isnan(input_temp))
     input_temp[indices] = 0.0
     if (np.sum(data[1]) > 0):
         geoDist = geodesic_distance.geodesic2d_raster_scan(
             input_temp, data[1], self.lambda_par, self.iterations)
     else:
         geoDist = np.float32(np.zeros(np.shape(data[0])))
     maxvalues = [np.max(geoDist)]
     return [geoDist, np.array([maxvalues])]
Ejemplo n.º 3
0
def geodesic_distance_2d(I, S, lamb, iter):
    '''
    get 2d geodesic disntance by raser scanning.
    I: input image
    S: binary image where non-zero pixels are used as seeds
    lamb: weighting betwween 0.0 and 1.0
          if lamb==0.0, return spatial euclidean distance without considering gradient
          if lamb==1.0, the distance is based on gradient only without using spatial distance
    iter: number of iteration for raster scanning.
    '''
    return geodesic_distance.geodesic2d_raster_scan(I, S, lamb, iter)
Ejemplo n.º 4
0
def test_geodesic_distance2d():
    I = np.asarray(Image.open('../data/img2d.png').convert('L'), np.float32)
    S = np.zeros_like(I, np.uint8)
    S[100][100] = 1
    t0 = time.time()
    D1 = geodesic_distance.geodesic2d_fast_marching(I, S)
    t1 = time.time()
    D2 = geodesic_distance.geodesic2d_raster_scan(I, S)
    dt1 = t1 - t0
    dt2 = time.time() - t1
    print "runtime(s) of fast marching {0:}".format(dt1)
    print "runtime(s) of raster  scan  {0:}".format(dt2)
    plt.subplot(1, 3, 1)
    plt.imshow(I)
    plt.subplot(1, 3, 2)
    plt.imshow(D1)
    plt.subplot(1, 3, 3)
    plt.imshow(D2)
    plt.show()
Ejemplo n.º 5
0
#python setup.py build
#python setup.py install

#python
import geodesic_distance
import scipy.misc
import numpy as np
import matplotlib.pyplot as plt
import scipy.ndimage as nd
I = np.float32(scipy.misc.ascent()) / 255.
Cost = nd.gaussian_gradient_magnitude(I, 1.)
Seed = np.zeros_like(Cost)
Seed[300, 300] = 1
A = geodesic_distance.geodesic2d_raster_scan(Cost, np.uint8(Seed))

plt.imshow(A)
plt.show()

I3 = np.stack([I[::2, ::2], I[::-2, ::2]], 2)
I3 = np.concatenate([I3, I3[:, :, ::-1]], 2)
I3 = np.concatenate([I3, I3[:, :, ::-1]], 2)
I3 = np.concatenate([I3, I3[:, :, ::-1]], 2)
I3 = np.concatenate([I3, I3[:, :, ::-1]], 2)
I3 = np.concatenate([I3, I3[:, :, ::-1]], 2)

Cost3 = nd.gaussian_gradient_magnitude(I3, 1.)
Seed3 = np.zeros_like(Cost3)
Seed3[150, 150, 32] = 1
A3 = geodesic_distance.geodesic3d_raster_scan(Cost3, np.uint8(Seed3), 1., 4.)
plt.imshow(A3[:, :, 32])
plt.show()