|
2 | 2 | import numpy as np
|
3 | 3 | import cupy as cp
|
4 | 4 | import matplotlib.pyplot as plt
|
| 5 | +plt.ioff() |
5 | 6 |
|
6 | 7 | size = (50, 50, 50)
|
7 | 8 | data = np.random.random(size).astype(np.float32)
|
| 9 | +rotation = np.random.uniform(0, 180, 3) |
| 10 | +scale = np.random.uniform(0.7, 1.3, 3) |
8 | 11 |
|
9 | 12 | rows = [
|
10 | 13 | [
|
|
24 | 27 | [
|
25 | 28 | {
|
26 | 29 | 'interpolation': 'linear',
|
27 |
| - 'device': 'gpu:0' |
| 30 | + 'device': 'gpu' |
28 | 31 | },
|
29 | 32 | {
|
30 | 33 | 'interpolation': 'bspline',
|
31 |
| - 'device': 'gpu:0' |
| 34 | + 'device': 'gpu' |
32 | 35 | },
|
33 | 36 | {
|
34 | 37 | 'interpolation': 'filt_bspline',
|
35 |
| - 'device': 'gpu:0' |
| 38 | + 'device': 'gpu' |
36 | 39 | },
|
37 | 40 | ]
|
38 | 41 | ]
|
39 | 42 |
|
| 43 | +### testing transforms methods |
40 | 44 | fig, ax = plt.subplots(len(rows), len(rows[0]), sharex=True, sharey=True)
|
41 | 45 | for i, r in enumerate(rows):
|
42 | 46 | for j, case in enumerate(r):
|
43 | 47 | print(f'Test case: {case["interpolation"]} / {case["device"]}')
|
44 |
| - tf = vt.transform(data, rotation=(0, 30, 0), interpolation=case['interpolation'], |
| 48 | + tf = vt.transform(data, rotation=rotation, scale=scale, interpolation=case['interpolation'], |
45 | 49 | profile=True, device=case['device'])
|
46 | 50 |
|
47 | 51 | ax[i][j].set_title(f'{case["interpolation"]} / {case["device"]}')
|
48 |
| - |
49 |
| - if isinstance(tf, cp.ndarray): |
50 |
| - ax[i][j].imshow(tf[size[0] // 2].get()) |
51 |
| - else: |
52 |
| - ax[i][j].imshow(tf[size[0] // 2]) |
| 52 | + ax[i][j].imshow(tf[size[0] // 2]) |
53 | 53 |
|
54 | 54 | plt.show()
|
55 | 55 |
|
56 | 56 |
|
| 57 | +### testing static volume methods |
| 58 | +print('\n\n\n') |
| 59 | +st_volumes = [ |
| 60 | + vt.StaticVolume(data, interpolation='linear', device='cpu'), |
| 61 | + vt.StaticVolume(data, interpolation='bspline', device='cpu'), |
| 62 | + vt.StaticVolume(data, interpolation='filt_bspline', device='cpu'), |
| 63 | + vt.StaticVolume(data, interpolation='linear', device='gpu'), |
| 64 | + vt.StaticVolume(data, interpolation='bspline', device='gpu'), |
| 65 | + vt.StaticVolume(data, interpolation='filt_bspline', device='gpu') |
| 66 | +] |
| 67 | + |
| 68 | +fig, ax = plt.subplots(2, 3, sharex=True, sharey=True) |
| 69 | + |
| 70 | +for n, v in enumerate(st_volumes): |
| 71 | + print(f'Test case: {v.interpolation} / {v.device}') |
| 72 | + tf = v.transform(scale=scale, rotation=rotation, profile=True) |
| 73 | + i, j = int(n / 3), n % 3 |
| 74 | + ax[i][j].set_title(f'{v.interpolation} / {v.device}') |
| 75 | + ax[i][j].imshow(tf[size[0] // 2]) |
| 76 | + |
| 77 | +plt.show() |
| 78 | + |
0 commit comments