Skip to content

Commit 7ad2db4

Browse files
committed
resample to spacing parallelized work
Signed-off-by: Jakub Mitura <jakub.mitura14@gmail.com>
1 parent 0da5761 commit 7ad2db4

File tree

5 files changed

+340
-272
lines changed

5 files changed

+340
-272
lines changed

src/Load_and_save.jl

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,20 @@ end
150150

151151

152152

153-
function update_voxel_data(old_image::MedImage, new_voxel_data::AbstractArray)
153+
function update_voxel_data(old_image, new_voxel_data::AbstractArray)
154154

155155
return MedImage(
156156
new_voxel_data,
157157
old_image.origin,
158158
old_image.spacing,
159159
old_image.direction,
160-
# old_image.spatial_metadata,
161-
old_image.image_type,
162-
old_image.image_subtype,
160+
instances(Image_type)[Int(old_image.image_type)+1],# Int(image.image_type),
161+
instances(Image_subtype)[Int(old_image.image_subtype)+1],# Int(image.image_subtype),
163162
# old_image.voxel_datatype,
164163
old_image.date_of_saving,
165164
old_image.acquistion_time,
166165
old_image.patient_id,
167-
old_image.current_device,
166+
instances(current_device_enum)[Int(old_image.current_device)+1], #Int(image.current_device),
168167
old_image.study_uid,
169168
old_image.patient_uid,
170169
old_image.series_uid,
@@ -177,22 +176,49 @@ function update_voxel_data(old_image::MedImage, new_voxel_data::AbstractArray)
177176

178177
end
179178

179+
function update_voxel_and_spatial_data(old_image, new_voxel_data::AbstractArray
180+
, new_origin, new_spacing, new_direction)
180181

181-
function update_voxel_and_spatial_data(old_image::MedImage, new_voxel_data::AbstractArray, new_origin, new_spacing, new_direction)
182-
183-
res = @set old_image.voxel_data = new_voxel_data
184-
res = @set res.origin = Utils.ensure_tuple(new_origin)
185-
res = @set res.spacing = Utils.ensure_tuple(new_spacing)
186-
res = @set res.direction = Utils.ensure_tuple(new_direction)
187-
# voxel_data=new_voxel_data
188-
# origin=new_origin
189-
# spacing=new_spacing
190-
# direction=new_direction
182+
return MedImage(
183+
new_voxel_data,
184+
new_origin,
185+
new_spacing,
186+
new_direction,
187+
# old_image.spatial_metadata,
188+
instances(Image_type)[Int(old_image.image_type)+1],# Int(image.image_type),
189+
instances(Image_subtype)[Int(old_image.image_subtype)+1],# Int(image.image_subtype),
190+
# old_image.voxel_datatype,
191+
old_image.date_of_saving,
192+
old_image.acquistion_time,
193+
old_image.patient_id,
194+
instances(current_device_enum)[Int(old_image.current_device)+1], #Int(image.current_device),
195+
old_image.study_uid,
196+
old_image.patient_uid,
197+
old_image.series_uid,
198+
old_image.study_description,
199+
old_image.legacy_file_name,
200+
old_image.display_data,
201+
old_image.clinical_data,
202+
old_image.is_contrast_administered,
203+
old_image.metadata)
191204

192-
# return @pack! old_image = voxel_data, origin, spacing, direction
193-
return res
194205
end
195206

207+
# function update_voxel_and_spatial_data(old_image, new_voxel_data::AbstractArray, new_origin, new_spacing, new_direction)
208+
209+
# res = @set old_image.voxel_data = new_voxel_data
210+
# res = @set res.origin = Utils.ensure_tuple(new_origin)
211+
# res = @set res.spacing = Utils.ensure_tuple(new_spacing)
212+
# res = @set res.direction = Utils.ensure_tuple(new_direction)
213+
# # voxel_data=new_voxel_data
214+
# # origin=new_origin
215+
# # spacing=new_spacing
216+
# # direction=new_direction
217+
218+
# # return @pack! old_image = voxel_data, origin, spacing, direction
219+
# return res
220+
# end
221+
196222
"""
197223
load image from path
198224
"""

src/Spatial_metadata_change.jl

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Spatial_metadata_change
22
using Interpolations
3-
using ..MedImage_data_struct, ..Utils, ..Orientation_dicts, ..Load_and_save
43

4+
using ..MedImage_data_struct, ..Utils, ..Orientation_dicts, ..Load_and_save
55
export change_orientation, resample_to_spacing
66
"""
77
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,
1212
ScaledInterpolation{T,N,typeof(itp),IT,typeof(ranges)}(itp, ranges)
1313
end
1414

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
1619
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])
1722
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))
1924
points_to_interpolate = get_base_indicies_arr(new_size)
2025

2126
points_to_interpolate = points_to_interpolate .- 1
2227
points_to_interpolate = points_to_interpolate .* new_spacing
2328
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)
2833

2934
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])
3536
new_im = Load_and_save.update_voxel_and_spatial_data(im, new_voxel_data, im.origin, new_spacing, im.direction)
3637

3738
return new_im
@@ -142,3 +143,19 @@ end#change_orientation
142143
# size(imm_res.voxel_data)
143144
# # range(1, stop=5, length=100,step=0.1)
144145
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

Comments
 (0)