|
| 1 | +.. _examples: |
| 2 | + |
| 3 | +******** |
| 4 | +Examples |
| 5 | +******** |
| 6 | + |
| 7 | +Retina Vessels |
| 8 | +============== |
| 9 | + |
| 10 | +Extracting the minimal path through the retina vessels with additional way points. |
| 11 | + |
| 12 | +.. plot:: |
| 13 | + |
| 14 | + from skimage.data import retina |
| 15 | + from skimage.color import rgb2gray |
| 16 | + from skimage.transform import rescale |
| 17 | + from skimage.filters import sato |
| 18 | + |
| 19 | + from skmpe import mpe |
| 20 | + |
| 21 | + image = rescale(rgb2gray(retina()), 0.5) |
| 22 | + speed_image = sato(image) |
| 23 | + |
| 24 | + start_point = (76, 388) |
| 25 | + end_point = (611, 442) |
| 26 | + way_points = [(330, 98), (554, 203)] |
| 27 | + |
| 28 | + path_info = mpe(speed_image, start_point, end_point, way_points) |
| 29 | + |
| 30 | + px, py = path_info.path[:, 1], path_info.path[:, 0] |
| 31 | + |
| 32 | + plt.imshow(image, cmap='gray') |
| 33 | + plt.plot(px, py, '-r') |
| 34 | + plt.plot(*start_point[::-1], 'oy') |
| 35 | + plt.plot(*end_point[::-1], 'og') |
| 36 | + for p in way_points: |
| 37 | + plt.plot(*p[::-1], 'ob') |
| 38 | + plt.axis('off') |
| 39 | +
|
| 40 | + |
| 41 | +Bricks |
| 42 | +====== |
| 43 | + |
| 44 | +Extracting the shortest paths through "bricks" image. |
| 45 | + |
| 46 | +.. plot:: |
| 47 | + |
| 48 | + from skimage.data import brick |
| 49 | + from skimage.transform import rescale |
| 50 | + from skimage.exposure import rescale_intensity, adjust_sigmoid |
| 51 | + |
| 52 | + from skmpe import parameters, mpe |
| 53 | + |
| 54 | + image = rescale(brick(), 0.5) |
| 55 | + speed_image = rescale_intensity( |
| 56 | + adjust_sigmoid(image, cutoff=0.5, gain=10).astype(np.float_), out_range=(0., 1.)) |
| 57 | + |
| 58 | + start_point = (44, 13) |
| 59 | + end_point = (233, 230) |
| 60 | + way_points = [(211, 59), (17, 164)] |
| 61 | + |
| 62 | + with parameters(integrate_max_step=1.0): |
| 63 | + path_info1 = mpe(speed_image, start_point, end_point) |
| 64 | + path_info2 = mpe(speed_image, start_point, end_point, way_points) |
| 65 | + |
| 66 | + px1, py1 = path_info1.path[:, 1], path_info1.path[:, 0] |
| 67 | + px2, py2 = path_info2.path[:, 1], path_info2.path[:, 0] |
| 68 | + |
| 69 | + plt.imshow(image, cmap='gray') |
| 70 | + plt.plot(px1, py1, '-r', linewidth=2) |
| 71 | + plt.plot(px2, py2, '--r', linewidth=2) |
| 72 | + |
| 73 | + plt.plot(*start_point[::-1], 'oy') |
| 74 | + plt.plot(*end_point[::-1], 'og') |
| 75 | + for p in way_points: |
| 76 | + plt.plot(*p[::-1], 'ob') |
| 77 | + plt.axis('off') |
0 commit comments