Skip to content

Commit

Permalink
Merge pull request #49 from HolyLab/teh/streamline_deps
Browse files Browse the repository at this point in the history
* Streamline dependencies
* Bump minimum Julia version to 1.6
* `abs2` transition
  • Loading branch information
timholy authored Jan 8, 2024
2 parents 9bd549b + 2df30ba commit a4ace5a
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 55 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.1'
- '1.6'
- '1'
# - 'nightly'
Expand Down
15 changes: 9 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name = "RegisterQD"
uuid = "ac24ea0c-1830-11e9-18d4-81f172323054"
version = "0.3.1"
version = "0.3.2"

[deps]
CenterIndexedArrays = "46a7138f-0d70-54e1-8ada-fb8296f91f24"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
Expand All @@ -23,22 +25,23 @@ AxisArrays = "0.3, 0.4"
CenterIndexedArrays = "0.2"
CoordinateTransformations = "0.5, 0.6"
Distributions = "0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
ImageCore = "0.10"
ImageMagick = "0.7, 1"
ImageMetadata = "0.9"
Images = "0.20, 0.21, 0.22, 0.23, 0.24, 0.25"
Interpolations = "0.12, 0.13, 0.14"
ImageTransformations = "0.10"
Interpolations = "0.12, 0.13, 0.14, 0.15"
MappedArrays = "0.2, 0.3, 0.4"
OffsetArrays = "0.11, 1"
PaddedViews = "0.4, 0.5"
QuadDIRECT = "0.0, 0.1"
QuadDIRECT = "0.1"
RegisterCore = "0.1, 0.2"
RegisterDeformation = "0.3, 0.4"
RegisterMismatch = "0.3, 0.4"
Rotations = "0.12, 0.13, 1"
StaticArrays = "0.11, 0.12, 1"
TestImages = "0.5, 0.6, 1"
Unitful = "0.17, 0.18, 1"
julia = "1"
julia = "1.6"

[extras]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down
12 changes: 7 additions & 5 deletions src/RegisterQD.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module RegisterQD

using Images, CoordinateTransformations, QuadDIRECT
using RegisterMismatchCommon
using RegisterCore
using ImageCore, ImageTransformations, ImageFiltering
using CoordinateTransformations
using QuadDIRECT
using RegisterMismatchCommon
using RegisterCore
using RegisterDeformation, PaddedViews, MappedArrays
using Rotations
using Interpolations, CenterIndexedArrays, StaticArrays, OffsetArrays
using LinearAlgebra

using Images.ImageTransformations: CornerIterator
using ImageTransformations: CornerIterator

const VecLike = Union{AbstractVector{<:Number}, Tuple{Number, Vararg{Number}}}

Expand All @@ -35,7 +37,7 @@ function qd_rigid(fixed, moving, mxshift::VecLike, mxrot::Union{Number,VecLike},
end

function qd_affine(fixed, moving, mxshift, linmins, linmaxs, SD;
thresh=0.5*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.5*sum(abs2.(fixed[.!(isnan.(fixed))])),
initial_tfm=IdentityTransformation(),
print_interval=100,
kwargs...)
Expand Down
6 changes: 3 additions & 3 deletions src/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ which is why this is "coarse" optimization.
function qd_affine_coarse(fixed, moving, mxshift, linmins, linmaxs;
SD=I,
initial_tfm=IdentityTransformation(),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
minwidth=default_lin_minwidths(moving),
maxevals=5e4,
kwargs...)
Expand Down Expand Up @@ -117,7 +117,7 @@ As a consequence, any large translations must be supplied with reasonable accura
function qd_affine_fine(fixed, moving, linmins, linmaxs;
SD=I,
initial_tfm=IdentityTransformation(),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
minwidth_mat=default_lin_minwidths(fixed)./10,
maxevals=5e4,
kwargs...)
Expand Down Expand Up @@ -184,7 +184,7 @@ overlap between the two images; with non-zero `thresh`, it is not permissible to
function qd_affine(fixed, moving, mxshift, linmins, linmaxs;
presmoothed=false,
SD=I,
thresh=0.5*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.5*sum(abs2.(fixed[.!(isnan.(fixed))])),
initial_tfm=IdentityTransformation(),
print_interval=100,
kwargs...)
Expand Down
9 changes: 4 additions & 5 deletions src/rigid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
function qd_rigid_coarse(fixed, moving, mxshift, mxrot, minwidth_rot;
SD=I,
initial_tfm=IdentityTransformation(),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
kwargs...)
#note: if a trial rotation results in image overlap < thresh for all possible shifts then QuadDIRECT throws an error
f(x) = rigid_mm_fast(x, mxshift, fixed, moving, thresh, SD; initial_tfm=initial_tfm)
Expand All @@ -104,7 +104,7 @@ end
function qd_rigid_fine(fixed, moving, mxrot, minwidth_rot;
SD=I,
initial_tfm=IdentityTransformation(),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
kwargs...)
f(x) = rigid_mm_slow(x, fixed, moving, thresh, SD; initial_tfm=initial_tfm)
upper_shft = fill(2.0, ndims(fixed))
Expand Down Expand Up @@ -179,15 +179,14 @@ function qd_rigid(fixed, moving, mxshift::VecLike, mxrot::Union{Number,VecLike};
presmoothed=false,
SD=I,
minwidth_rot=default_minwidth_rot(CartesianIndices(fixed), SD),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
initial_tfm=IdentityTransformation(),
print_interval=100,
kwargs...)
#TODO make sure isrotation(initial_tfm.linear) returns true, else throw a warning and an option to terminate? do I still allow the main block to run?
if initial_tfm == IdentityTransformation() || isrotation(initial_tfm.linear)
else
@show "WARNING: initial_tfm is not a rigid transformation"
# @warn "initial_tfm is not a rigid transformation"
@warn "initial_tfm is not a rigid transformation"
end
fixed, moving = float(fixed), float(moving)
if presmoothed
Expand Down
4 changes: 2 additions & 2 deletions src/translations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
function qd_translate_fine(fixed, moving;
initial_tfm=IdentityTransformation(),
minwidth=fill(0.01, ndims(fixed)),
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
kwargs...)
f(x) = translate_mm_slow(x, fixed, moving, thresh; initial_tfm=initial_tfm)
upper = fill(1.0, ndims(fixed))
Expand Down Expand Up @@ -56,7 +56,7 @@ that can occur due to normalization when the transformed `moving` doesn't fully
"""
function qd_translate(fixed, moving, mxshift;
presmoothed=false,
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
initial_tfm=IdentityTransformation(),
minwidth=fill(0.01, ndims(fixed)), print_interval=100, crop=false, kwargs...)
fixed, moving = float(fixed), float(moving)
Expand Down
4 changes: 0 additions & 4 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,3 @@ function _analyze(f, lower, upper; kwargs...)
QuadDIRECT.analyze(f, splits, lower, upper; kwargs...)
end

# abs2 was removed in https://github.com/JuliaGraphics/ColorVectorSpace.jl/pull/131
# this is the current recommended replacement
# TODO: follow https://github.com/JuliaGraphics/ColorVectorSpace.jl/issues/157 and adjust for changes
_abs2(c) = mapreducec(v->float(v)^2, +, float(zero(eltype(c))), c)
14 changes: 8 additions & 6 deletions test/gpu_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using ImageMagick
using Distributions #what is this?
using RegisterQD.StaticArrays
using RegisterQD.Interpolations
using RegisterQD.Images
using RegisterQD.ImageCore
using RegisterQD.ImageTransformations
using RegisterQD.ImageFiltering
using RegisterQD.CoordinateTransformations
using RegisterQD.Rotations
using RegisterQD.OffsetArrays
Expand Down Expand Up @@ -32,7 +34,7 @@ to_affine(tfm::Translation) = AffineMap(Matrix{Float64}(LinearAlgebra.I, length(
to_affine(tfm::LinearMap) = AffineMap(Matrix{Float64}(LinearAlgebra.I, length(tfm.translation), length(tfm.translation)), tfm.translation)
to_affine(tfm::AffineMap) = tfm

#Helper to test that a found transform is (roughly) the inverse of the original transform.
#Helper to test that a found transform is (roughly) the inverse of the original transform.
function tfmtest(tfm, tfminv)
comp = to_affine(tfm tfminv) #should be the identity transform
diagtol = 0.005
Expand All @@ -47,7 +49,7 @@ end
# cu_wrap(img::OffsetArray) = OffsetArray(CuArray(img.parent), img.offsets)
# cu_wrap(img) = CuArray(img)

#rigid tests
#rigid tests
img = Float32.(testimage("cameraman"))
SD = Matrix{Float64}(LinearAlgebra.I, 2, 2)
tfm = Translation(@SVector([14, 17]))LinearMap(RotMatrix(0.3)) #no distortion for now
Expand All @@ -60,7 +62,7 @@ minwidth_rot = fill(0.002, 3)

tform, mm = qd_rigid(fixed, moving, mxshift, mxrot; SD=SD, maxevals=1000, rtol=0, fvalue=0.0002);

tfmtest(tfm, tform)
tfmtest(tfm, tform)
@test mm<0.001


Expand All @@ -70,10 +72,10 @@ tfm3D = Translation(@SVector([15, 10, 2]))∘LinearMap(RotXYZ(0.05, 0.02, 0)) #n
fixed, moving = fixedmov(centered(img3D), tfm3D)
mxshift = (30, 30, 5) #make sure this isn't too small
mxrot = (0.1, 0.1, 0.1)
minwidth_rot = fill(0.002, 3)
minwidth_rot = fill(0.002, 3)

tform2, mm2 = qd_rigid(fixed, moving, mxshift, mxrot; SD=SD3D, maxevals=1000, rtol=0, fvalue=0.0002);
tfmtest(tfm3D, tform2)
tfmtest(tfm3D, tform2)
@test mm2<0.01

#Coppied over from qd_random
Expand Down
21 changes: 8 additions & 13 deletions test/initial_tfm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ using RegisterQD
using LinearAlgebra
using RegisterQD.StaticArrays
using RegisterQD.Interpolations
using RegisterQD.Images
using RegisterQD.ImageCore
using RegisterQD.ImageTransformations
using RegisterQD.ImageFiltering
using RegisterQD.CoordinateTransformations
using RegisterQD.Rotations
using Test

g = 0.2:0.2:1.2
gradcube = g .* reshape(g, 1, 6) .* reshape(g, 1, 1, 6)
Expand Down Expand Up @@ -144,21 +147,13 @@ end
@test !isrotation(SD*tformtest77.linear*inv(SD))
#fails due to specific error in qd_rigid_fine

# a non rigid initial_tfm does not return a rigid transformation and prints an error message (?)
tformtest8, mm8 = qd_rigid(testimage6, testimage5, mxshift, mxrot2; SD=SD, print_interval=typemax(Int), initial_tfm = AffineMap(SD\tformtest5.linear*SD, SD\tformtest5.translation))
# a non rigid initial_tfm does not return a rigid transformation and prints a warning
tformtest8, mm8 = @test_logs (:warn, "initial_tfm is not a rigid transformation") begin
qd_rigid(testimage6, testimage5, mxshift, mxrot2; SD=SD, print_interval=typemax(Int), initial_tfm = AffineMap(SD\tformtest5.linear*SD, SD\tformtest5.translation))
end
@test mm8 <1e-4
@test isapprox(tformtest8, mytform, atol = 1)
@test !isrotation(tformtest8.linear)

mktemp() do path, io
redirect_stdout(io) do
tformtest8, mm8 = qd_rigid(testimage6, testimage5, mxshift, mxrot2; SD=SD, print_interval=typemax(Int), initial_tfm = AffineMap(SD\tformtest5.linear*SD, SD\tformtest5.translation))
end
flush(io)
str = read(path, String)
@test !isempty(str)
end

end

@testset "Test initial_tfm improves translational alignment for affine" begin
Expand Down
19 changes: 10 additions & 9 deletions test/qd_random.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using RegisterQD
using RegisterQD.StaticArrays
using RegisterQD.Interpolations
using RegisterQD.Images
using RegisterQD.ImageCore
using RegisterQD.ImageTransformations
using RegisterQD.ImageFiltering
using RegisterQD.CoordinateTransformations
using RegisterQD.Rotations
using RegisterQD: _abs2
using Random

#import BlockRegistration, RegisterOptimize
Expand All @@ -23,7 +24,7 @@ using Test, TestImages
itp = interpolate(newfixed, BSpline(Linear()))
etp = extrapolate(itp, NaN)
fixed = etp(Base.axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
mxshift = (10,10)

tfm, mm = qd_translate(fixed, moving, mxshift; maxevals=1000, thresh=thresh, rtol=0)
Expand All @@ -41,7 +42,7 @@ using Test, TestImages
itp = interpolate(newfixed, BSpline(Linear()))
etp = extrapolate(itp, NaN)
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
mxshift = (5,5,5)

tfm, mm = qd_translate(fixed, moving, mxshift; maxevals=1000, thresh=thresh, rtol=0)
Expand All @@ -56,7 +57,7 @@ using Test, TestImages
itp = interpolate(newfixed, BSpline(Linear()))
etp = extrapolate(itp, NaN)
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
mxshift = (10,10)
mxrot = pi/90
minwidth_rot = [0.0002]
Expand All @@ -73,7 +74,7 @@ using Test, TestImages
itp = interpolate(newfixed, BSpline(Linear()))
etp = extrapolate(itp, NaN)
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
mxshift = (5,5,5)
mxrot = [pi/90; pi/90; pi/90]
minwidth_rot = fill(0.0002, 3)
Expand All @@ -95,7 +96,7 @@ using Test, TestImages
itp = interpolate(newfixed, BSpline(Linear()))
etp = extrapolate(itp, NaN)
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
thresh = 0.5 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
thresh = 0.5 * sum(abs2.(fixed[.!(isnan.(fixed))]))
mxshift = (5,5)
SD = SDiagonal(@SVector(ones(ndims(fixed))))

Expand All @@ -118,7 +119,7 @@ using Test, TestImages
#inds = intersect.(axes(moving), axes(newfixed))
#fixed = newfixed[inds...]
#moving = moving[inds...]
#thresh = 0.1 * (sum(_abs2.(fixed[.!(isnan.(fixed))]))+sum(_abs2.(moving[.!(isnan.(moving))])));
#thresh = 0.1 * (sum(abs2.(fixed[.!(isnan.(fixed))]))+sum(abs2.(moving[.!(isnan.(moving))])));
#mxshift = (10,10,10)
#SD = eye(ndims(fixed));

Expand All @@ -141,7 +142,7 @@ using Test, TestImages
#inds = intersect.(axes(moving), axes(newfixed))
#fixed = newfixed[inds...]
#moving = moving[inds...]
#thresh = 0.5 * sum(_abs2.(fixed[.!(isnan.(fixed))]));
#thresh = 0.5 * sum(abs2.(fixed[.!(isnan.(fixed))]));
#mxshift = (5,5,5)
#SD = eye(ndims(fixed));
#@test RegisterOptimize.aff(vcat(tfm00.translation[:], tfm00.linear[:]), fixed, SD) == tfm0
Expand Down
4 changes: 3 additions & 1 deletion test/qd_standard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using ImageMagick
using Distributions
using RegisterQD.StaticArrays
using RegisterQD.Interpolations
using RegisterQD.Images
using RegisterQD.ImageCore
using RegisterQD.ImageTransformations
using RegisterQD.ImageFiltering
using RegisterQD.CoordinateTransformations
using RegisterQD.Rotations
using RegisterQD.OffsetArrays
Expand Down

0 comments on commit a4ace5a

Please sign in to comment.