1
1
module Spatial_metadata_change
2
2
using Interpolations
3
- using .. MedImage_data_struct, .. Utils, .. Orientation_dicts, .. Load_and_save
4
3
4
+ using .. MedImage_data_struct, .. Utils, .. Orientation_dicts, .. Load_and_save
5
5
export change_orientation, resample_to_spacing
6
6
"""
7
7
given a MedImage object and desired spacing (spacing) return the MedImage object with the new spacing
@@ -12,26 +12,27 @@ function scale(itp::AbstractInterpolation{T,N,IT}, ranges::Vararg{AbstractRange,
12
12
ScaledInterpolation {T,N,typeof(itp),IT,typeof(ranges)} (itp, ranges)
13
13
end
14
14
15
- function resample_to_spacing (im:: MedImage , new_spacing:: Tuple{Float64,Float64,Float64} , interpolator_enum:: Interpolator_enum ):: MedImage
15
+
16
+
17
+
18
+ function resample_to_spacing (im, new_spacing:: Tuple{Float64, Float64, Float64} , interpolator_enum,use_cuda= false ):: MedImage
16
19
old_spacing = im. spacing
20
+ old_spacing= (old_spacing[3 ],old_spacing[2 ],old_spacing[1 ])
21
+ new_spacing= (new_spacing[3 ],new_spacing[2 ],new_spacing[1 ])
17
22
old_size = size (im. voxel_data)
18
- new_size = Tuple {Int,Int,Int} (ceil .((old_size .* old_spacing) ./ new_spacing))
23
+ new_size = Tuple {Int, Int, Int} (ceil .((old_size .* old_spacing) ./ new_spacing))
19
24
points_to_interpolate = get_base_indicies_arr (new_size)
20
25
21
26
points_to_interpolate = points_to_interpolate .- 1
22
27
points_to_interpolate = points_to_interpolate .* new_spacing
23
28
points_to_interpolate = points_to_interpolate .+ 1
24
-
25
- # print("\n ppppp $( points_to_interpolate) \n " )
26
-
27
- interpolated_points = interpolate_my (points_to_interpolate, im. voxel_data, old_spacing, interpolator_enum, true )
29
+ # if(use_cuda)
30
+ # points_to_interpolate = CuArray(points_to_interpolate )
31
+ # end
32
+ interpolated_points = interpolate_my (points_to_interpolate, im. voxel_data, old_spacing, interpolator_enum, true , 0 , true )
28
33
29
34
new_voxel_data = reshape (interpolated_points, (new_size[1 ], new_size[2 ], new_size[3 ]))
30
- # Check if array a and b have the same type
31
- # new_voxel_data=cast_to_array_b_type(new_voxel_data,im.voxel_data)
32
-
33
-
34
- # Create the new MedImage object
35
+ new_spacing= (new_spacing[3 ],new_spacing[2 ],new_spacing[1 ])
35
36
new_im = Load_and_save. update_voxel_and_spatial_data (im, new_voxel_data, im. origin, new_spacing, im. direction)
36
37
37
38
return new_im
@@ -142,3 +143,19 @@ end#change_orientation
142
143
# size(imm_res.voxel_data)
143
144
# # range(1, stop=5, length=100,step=0.1)
144
145
end # Spatial_metadata_change
146
+
147
+
148
+
149
+ # using KernelAbstractions, Test
150
+ # @kernel function mul2_kernel(A)
151
+ # I = @index(Global)
152
+ # shared_arr=@localmem(Float32, (512,3))
153
+ # index_local = @index(Local, Linear)
154
+ # A[index_local] = 2 * A[I]
155
+ # end
156
+
157
+ # dev = CPU()
158
+ # A = ones(1024, 1024)
159
+ # ev = mul2_kernel(dev, 64)(A, ndrange=size(A))
160
+ # synchronize(dev)
161
+ # all(A .== 2.0)
0 commit comments