How can I register/align shifted image stacks?

Did you do ?qd_rigid? There is quite a lot of help in the functions of the package. Though it looks like some things are still not documented, e.g. mm is the mismatch, essentially the mean-square difference.

Here’s an example using the “mri” image in TestImages.jl. (You don’t expect alignment of these images, this is just for demonstration purposes.)

julia> using TestImages, RegisterQD

julia> mri = testimage("mri");

julia> fixed = mri[:,:,1];

julia> for i = 2:size(mri,3)
           moving = mri[:,:,i]
           tfm, mm = qd_rigid(fixed, moving, (5,5), 0.1, print_interval=typemax(Int))
           @show i tfm mm
       end
i = 2
tfm = AffineMap([0.9999999989634472 -4.5531370764914994e-5; 4.5531370764914994e-5 0.9999999989634472], [0.5040017264556756, 0.2990075519981027])
mm = 0.09511831219416511
i = 3
tfm = AffineMap([0.9999994381696169 -0.0010600285140643243; 0.0010600285140643243 0.9999994381696169], [2.5874336682326287, 0.4090526341672306])
mm = 0.2142679963090935
i = 4
tfm = AffineMap([0.9999981403042801 -0.0019285714871368261; 0.0019285714871368261 0.9999981403042801], [4.830450516702656, -0.7747954743088441])
mm = 0.2715531457442805

and so on. Use warp to apply a transformation to the image:

julia> using Images, ImageView

julia> moving = mri[:,:,5];

julia> tfm, mm = qd_rigid(fixed, moving, (5,5), 0.1, print_interval=typemax(Int))
(AffineMap([0.9996029561869612 0.02817676316201408; -0.02817676316201408 0.9996029561869612], [5.002439810122244, 5.099462334279371]), 0.2706807127431129)

julia> movw = warp(moving, tfm, axes(fixed));

julia> imshow(colorview(RGB, fixed, moving, zeroarray); name="original")

julia> imshow(colorview(RGB, fixed, movw, zeroarray); name="rigid");

original rigid
(Left is original, right is rigid-warping.)

1 Like