Skip to content

Commit

Permalink
Add l1 bounding box keep ellipsoid inside volume
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljuerss committed Mar 1, 2024
1 parent 6ff221d commit b34f8d5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ function scaleValue(x::T, a::Real, b::Real=one(T)) where {T <: Real}
return a + (x*(b-a))
end

radius_scaled_unit_vector(radius::NTuple{D, <:Real}, i::Int) where D = ntuple(j -> i == j ? radius[i] : 0.0, D)
rotate_vector(v::NTuple{3, <:Real}, rotAngles::NTuple{3, <:Real}) = ImagePhantoms.Rxyz_mul(v, rotAngles...)
rotate_vector(v::NTuple{2, <:Real}, rotAngles::NTuple{1, <:Real}) = ImagePhantoms.rotate2d(v, rotAngles...)

function bbox(radius::NTuple{Dr,<:Real}, rotAngles::NTuple{Da,<:Real}) where {Dr,Da}
matTest = zeros(Float64, (Dr,Dr))
for i=1:Dr
r_i = radius_scaled_unit_vector(radius, i)
matTest[i,:] = abs.([rotate_vector(r_i, rotAngles)...])
end
boundBox = [maximum(matTest[:,i]) for i=1:Dr]
return boundBox
end

"""
ellipsoidPhantom(
N::NTuple{D,Int};
Expand Down Expand Up @@ -50,7 +64,11 @@ function ellipsoidPhantom(N::NTuple{D,Int}; rng::AbstractRNG = GLOBAL_RNG,
# in 2D there is just one rotational degree of freedom
rotAngles = ntuple(_ -> 2π*rand(rng), D == 2 ? 1 : D)
radius = N .* scaleValue.(ntuple(_ -> 0.3*rand(rng), D), minRadius./N)
shift = N .* ntuple(_ -> 0.6*(rand(rng)-0.5), D)
shift = N .* ntuple(_ -> 0.6*(rand(rng)-0.5), D)
safety_margin_shift = 1.0
# clip shift to ensure that the object is fully inside the image
bb = bbox(radius, rotAngles)
shift = ntuple(i -> (bb[i]+abs(shift[i]) < (N[i]/2 - 1.0)*safety_margin_shift) ? shift[i] : (N[i]/2 - bb[i] - 1.0)*sign(shift[i])*safety_margin_shift, D)
value = scaleValue.(rand(rng, 1), minValue)#.^2
kernelWidth = ntuple(_ -> rand(rng)*N[1] / 20, D)
P = singleEllipsoid(N, radius, shift, rotAngles)
Expand Down

0 comments on commit b34f8d5

Please sign in to comment.