Commit 81b99bfa02345b83b75488a535a9bd85f49d65e6
1 parent
4cf10836
Exists in
master
and in
6 other branches
ADD: Reduced Matrix slice by slice
Showing
1 changed file
with
25 additions
and
9 deletions
Show diff stats
invesalius/data/imagedata_utils.py
... | ... | @@ -4,25 +4,41 @@ import vtk |
4 | 4 | # TODO: Test cases which are originally in sagittal/coronal orientation |
5 | 5 | # and have gantry |
6 | 6 | |
7 | -def ResampleMatrix(imagedata, value): | |
7 | +def ResampleMatrix(imagedata, xy_dimension): | |
8 | 8 | """ |
9 | 9 | Resample vtkImageData matrix. |
10 | 10 | """ |
11 | - spacing = imagedata.GetSpacing() | |
12 | 11 | extent = imagedata.GetExtent() |
13 | - size = imagedata.GetDimensions() | |
12 | + spacing = imagedata.GetSpacing() | |
14 | 13 | |
15 | - width = float(size[0]) | |
16 | - height = float(size[1]/value) | |
14 | + if extent[1]==extent[3]: | |
15 | + f = extent[1] | |
16 | + x = 0 | |
17 | + y = 1 | |
17 | 18 | |
18 | - resolution = (height/(extent[1]-extent[0])+1)*spacing[1] | |
19 | + elif extent[1]==extent[5]: | |
20 | + f = extent[1] | |
21 | + x=0 | |
22 | + y=2 | |
19 | 23 | |
24 | + elif extent[3]==extent[5]: | |
25 | + f = extent[3] | |
26 | + x = 1 | |
27 | + y = 2 | |
28 | + | |
29 | + factor = xy_dimension/float(f+1) | |
30 | + | |
20 | 31 | resample = vtk.vtkImageResample() |
21 | 32 | resample.SetInput(imagedata) |
22 | - resample.SetAxisMagnificationFactor(0, resolution) | |
23 | - resample.SetAxisMagnificationFactor(1, resolution) | |
24 | - | |
33 | + resample.SetAxisMagnificationFactor(0, factor) | |
34 | + resample.SetAxisMagnificationFactor(1, factor) | |
35 | + resample.SetOutputSpacing(spacing[0] * factor, spacing[1] * factor, spacing[2]) | |
36 | + resample.Update() | |
37 | + | |
38 | + | |
25 | 39 | return resample.GetOutput() |
40 | + | |
41 | + | |
26 | 42 | |
27 | 43 | def FixGantryTilt(imagedata, tilt): |
28 | 44 | """ | ... | ... |