Skip to content

Commit ad93629

Browse files
Fix abs2 (#36)
1 parent e5ed603 commit ad93629

File tree

6 files changed

+23
-17
lines changed

6 files changed

+23
-17
lines changed

src/RegisterQD.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function qd_rigid(fixed, moving, mxshift::VecLike, mxrot::Union{Number,VecLike},
3535
end
3636

3737
function qd_affine(fixed, moving, mxshift, linmins, linmaxs, SD;
38-
thresh=0.5*sum(abs2.(fixed[.!(isnan.(fixed))])),
38+
thresh=0.5*sum(_abs2.(fixed[.!(isnan.(fixed))])),
3939
initial_tfm=IdentityTransformation(),
4040
print_interval=100,
4141
kwargs...)

src/affine.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ which is why this is "coarse" optimization.
8484
function qd_affine_coarse(fixed, moving, mxshift, linmins, linmaxs;
8585
SD=I,
8686
initial_tfm=IdentityTransformation(),
87-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
87+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
8888
minwidth=default_lin_minwidths(moving),
8989
maxevals=5e4,
9090
kwargs...)
@@ -117,7 +117,7 @@ As a consequence, any large translations must be supplied with reasonable accura
117117
function qd_affine_fine(fixed, moving, linmins, linmaxs;
118118
SD=I,
119119
initial_tfm=IdentityTransformation(),
120-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
120+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
121121
minwidth_mat=default_lin_minwidths(fixed)./10,
122122
maxevals=5e4,
123123
kwargs...)
@@ -184,7 +184,7 @@ overlap between the two images; with non-zero `thresh`, it is not permissible to
184184
function qd_affine(fixed, moving, mxshift, linmins, linmaxs;
185185
presmoothed=false,
186186
SD=I,
187-
thresh=0.5*sum(abs2.(fixed[.!(isnan.(fixed))])),
187+
thresh=0.5*sum(_abs2.(fixed[.!(isnan.(fixed))])),
188188
initial_tfm=IdentityTransformation(),
189189
print_interval=100,
190190
kwargs...)

src/rigid.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ end
8686
function qd_rigid_coarse(fixed, moving, mxshift, mxrot, minwidth_rot;
8787
SD=I,
8888
initial_tfm=IdentityTransformation(),
89-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
89+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
9090
kwargs...)
9191
#note: if a trial rotation results in image overlap < thresh for all possible shifts then QuadDIRECT throws an error
9292
f(x) = rigid_mm_fast(x, mxshift, fixed, moving, thresh, SD; initial_tfm=initial_tfm)
@@ -104,7 +104,7 @@ end
104104
function qd_rigid_fine(fixed, moving, mxrot, minwidth_rot;
105105
SD=I,
106106
initial_tfm=IdentityTransformation(),
107-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
107+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
108108
kwargs...)
109109
f(x) = rigid_mm_slow(x, fixed, moving, thresh, SD; initial_tfm=initial_tfm)
110110
upper_shft = fill(2.0, ndims(fixed))
@@ -179,7 +179,7 @@ function qd_rigid(fixed, moving, mxshift::VecLike, mxrot::Union{Number,VecLike};
179179
presmoothed=false,
180180
SD=I,
181181
minwidth_rot=default_minwidth_rot(CartesianIndices(fixed), SD),
182-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
182+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
183183
initial_tfm=IdentityTransformation(),
184184
print_interval=100,
185185
kwargs...)

src/translations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616
function qd_translate_fine(fixed, moving;
1717
initial_tfm=IdentityTransformation(),
1818
minwidth=fill(0.01, ndims(fixed)),
19-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
19+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
2020
kwargs...)
2121
f(x) = translate_mm_slow(x, fixed, moving, thresh; initial_tfm=initial_tfm)
2222
upper = fill(1.0, ndims(fixed))
@@ -50,13 +50,13 @@ If you have a good initial guess at the solution, pass it with the `initial_tfm`
5050
`thresh` enforces a certain amount of sum-of-squared-intensity overlap between the two images;
5151
with non-zero `thresh`, it is not permissible to "align" the images by shifting one entirely out of the way of the other.
5252
53-
If the `crop` keyword arg is `true` then `fixed` is cropped by `mxshift` (after the optional `initial_tfm`) on all sides
53+
If the `crop` keyword arg is `true` then `fixed` is cropped by `mxshift` (after the optional `initial_tfm`) on all sides
5454
so that there will be complete overlap between `fixed` and `moving` for any evaluated shift. This avoids edge effects
5555
that can occur due to normalization when the transformed `moving` doesn't fully overlap with `fixed`.
5656
"""
5757
function qd_translate(fixed, moving, mxshift;
5858
presmoothed=false,
59-
thresh=0.1*sum(abs2.(fixed[.!(isnan.(fixed))])),
59+
thresh=0.1*sum(_abs2.(fixed[.!(isnan.(fixed))])),
6060
initial_tfm=IdentityTransformation(),
6161
minwidth=fill(0.01, ndims(fixed)), print_interval=100, crop=false, kwargs...)
6262
fixed, moving = float(fixed), float(moving)

src/util.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,8 @@ function _analyze(f, lower, upper; kwargs...)
240240
splits = ([[lower[i]; lower[i]+(upper[i]-lower[i])/2; upper[i]] for i=1:length(lower)]...,)
241241
QuadDIRECT.analyze(f, splits, lower, upper; kwargs...)
242242
end
243+
244+
# abs2 was removed in https://github.com/JuliaGraphics/ColorVectorSpace.jl/pull/131
245+
# this is the current recommended replacement
246+
# TODO: follow https://github.com/JuliaGraphics/ColorVectorSpace.jl/issues/157 and adjust for changes
247+
_abs2(c) = mapreducec(v->float(v)^2, +, float(zero(eltype(c))), c)

test/qd_random.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using RegisterQD.Images
55
using RegisterQD.CoordinateTransformations
66
using RegisterQD.Rotations
77
using RegisterQD.RegisterMismatch
8+
using RegisterQD: _abs2
89
using Random
910

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

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

4748
tfm, mm = qd_translate(fixed, moving, mxshift; maxevals=1000, thresh=thresh, rtol=0)
@@ -56,7 +57,7 @@ using Test, TestImages
5657
itp = interpolate(newfixed, BSpline(Linear()))
5758
etp = extrapolate(itp, NaN)
5859
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
59-
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
60+
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
6061
mxshift = (10,10)
6162
mxrot = pi/90
6263
minwidth_rot = [0.0002]
@@ -73,7 +74,7 @@ using Test, TestImages
7374
itp = interpolate(newfixed, BSpline(Linear()))
7475
etp = extrapolate(itp, NaN)
7576
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
76-
thresh = 0.1 * sum(abs2.(fixed[.!(isnan.(fixed))]))
77+
thresh = 0.1 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
7778
mxshift = (5,5,5)
7879
mxrot = [pi/90; pi/90; pi/90]
7980
minwidth_rot = fill(0.0002, 3)
@@ -95,7 +96,7 @@ using Test, TestImages
9596
itp = interpolate(newfixed, BSpline(Linear()))
9697
etp = extrapolate(itp, NaN)
9798
fixed = etp(axes(moving)...) #often the warped array has one-too-many pixels in one or more dimensions due to extrapolation
98-
thresh = 0.5 * sum(abs2.(fixed[.!(isnan.(fixed))]))
99+
thresh = 0.5 * sum(_abs2.(fixed[.!(isnan.(fixed))]))
99100
mxshift = (5,5)
100101
SD = SDiagonal(@SVector(ones(ndims(fixed))))
101102

@@ -118,7 +119,7 @@ using Test, TestImages
118119
#inds = intersect.(axes(moving), axes(newfixed))
119120
#fixed = newfixed[inds...]
120121
#moving = moving[inds...]
121-
#thresh = 0.1 * (sum(abs2.(fixed[.!(isnan.(fixed))]))+sum(abs2.(moving[.!(isnan.(moving))])));
122+
#thresh = 0.1 * (sum(_abs2.(fixed[.!(isnan.(fixed))]))+sum(_abs2.(moving[.!(isnan.(moving))])));
122123
#mxshift = (10,10,10)
123124
#SD = eye(ndims(fixed));
124125

@@ -141,7 +142,7 @@ using Test, TestImages
141142
#inds = intersect.(axes(moving), axes(newfixed))
142143
#fixed = newfixed[inds...]
143144
#moving = moving[inds...]
144-
#thresh = 0.5 * sum(abs2.(fixed[.!(isnan.(fixed))]));
145+
#thresh = 0.5 * sum(_abs2.(fixed[.!(isnan.(fixed))]));
145146
#mxshift = (5,5,5)
146147
#SD = eye(ndims(fixed));
147148
#@test RegisterOptimize.aff(vcat(tfm00.translation[:], tfm00.linear[:]), fixed, SD) == tfm0

0 commit comments

Comments
 (0)