Test Registration Functions

In this example page I will show how the registration algorithms (lap, pflap, sparse_lap and sparse_pflap) perform. I will will show their speed and the quality of their outputs.

First I some testing images:

# using the package and TimerOutputs
using LAP_julia, TimerOutputs

# default arguments:
img, imgw, flow = gen_init();

See the Basic Interaction section or the Public Documentation for more advanced input generation

These are the differences between the target (img) and source (imgw) images.

imgoverlay(img, imgw, figtitle="Target vs Source")

test_registration_alg

This function times the registration algorithm on the inside and then test the output flow - flow_est and aligned source - source_reg.

# choose a method
method = sparse_pflap
# start a timer
timer = TimerOutput("ALG: " * string(method))
# set the keyword arguments of the method
method_kwargs = Dict(:display => false, :timer => timer, :match_source_histogram => false)
# set the arguments of the method if any
method_args = []
# start the test
flow_est, source_reg, timer, results = test_registration_alg(method,
                                                             img,
                                                             imgw,
                                                             flow,
                                                             timer=timer,
                                                             method_args=method_args,
                                                             only_flow_compare=false, # this adds source reg tests.
                                                             method_kwargs=method_kwargs);
 ──────────────────────────────────────────────────────────────────────────────
                                       Time                   Allocations
                               ──────────────────────   ───────────────────────
       Tot / % measured:            353ms / 96.3%            167MiB / 96.3%

 Section               ncalls     time   %tot     avg     alloc   %tot      avg
 ──────────────────────────────────────────────────────────────────────────────
 ALG: sparse_pflap          1    340ms   100%   340ms    161MiB  100%    161MiB
   single filter py...      7    321ms  94.6%  45.9ms    154MiB  96.2%  22.1MiB
     single lap at ...      7    287ms  84.6%  41.1ms    121MiB  75.6%  17.4MiB
       filtering            7    238ms  70.2%  34.1ms   68.2MiB  42.5%  9.75MiB
       prepare A and b      7   26.3ms  7.73%  3.75ms   41.7MiB  25.9%  5.95MiB
         window sum...     21   15.6ms  4.59%   743μs   25.0MiB  15.6%  1.19MiB
         window sum...     14   10.6ms  3.13%   759μs   16.6MiB  10.4%  1.19MiB
       multi mat div        7    120μs  0.04%  17.2μs    298KiB  0.18%  42.5KiB
       calculate flow       7   26.9μs  0.01%  3.84μs   49.9KiB  0.03%  7.13KiB
     image interpol...      7   19.3ms  5.69%  2.76ms   21.0MiB  13.1%  3.00MiB
     flow interpola...      7   13.8ms  4.05%  1.97ms   11.7MiB  7.28%  1.67MiB
     filter inds            7    272μs  0.08%  38.9μs    245KiB  0.15%  35.0KiB
   setup                    1   18.1ms  5.34%  18.1ms   6.13MiB  3.82%  6.13MiB
     find edge points       1   17.2ms  5.06%  17.2ms   4.13MiB  2.57%  4.13MiB
 ──────────────────────────────────────────────────────────────────────────────
  mse            | 0.001
  rmse           | 0.023
  time           | 0.34
  ncc            | 0.993
  flow_mae       | 0.144
  angle-rmse     | 30.816
  angle-mae      | 4.322
  mae            | 0.012
  flow_rmse      | 0.032

Check the generated flow and the original flow:

Ground Truth:

showflow(flow.*(-1), figtitle="Ground Truth")

Estimated Flow:

showflow(flow_est, figtitle="Estimated Flow")

Compare it with the pflap function

method = pflap
# same inputs, new timer
timer = TimerOutput("ALG: " * string(method))
flow_est, source_reg, timer, results = test_registration_alg(method,
                                                             img,
                                                             imgw,
                                                             flow,
                                                             timer=timer,
                                                             method_args=method_args,
                                                             only_flow_compare=false, # this adds source reg tests.
                                                             method_kwargs=method_kwargs);
 ─────────────────────────────────────────────────────────────────────
                              Time                   Allocations
                      ──────────────────────   ───────────────────────
   Tot / % measured:       1.26s / 99.1%            692MiB / 99.1%

 Section      ncalls     time   %tot     avg     alloc   %tot      avg
 ─────────────────────────────────────────────────────────────────────
 ALG: pflap        1    1.25s   100%   1.25s    686MiB  100%    686MiB
 ─────────────────────────────────────────────────────────────────────
  mse            | 0.0
  rmse           | 0.022
  time           | 1.246
  ncc            | 0.994
  flow_mae       | 0.214
  angle-rmse     | 20.649
  angle-mae      | 3.722
  mae            | 0.012
  flow_rmse      | 0.083

Check the generated flow and the original flow:

Ground Truth:

showflow(flow.*(-1), figtitle="Ground Truth")

Estimated Flow:

showflow(flow_est, figtitle="Estimated Flow")

The time_reg_alg is used to time the registration algorithm, when the original flow isn't known.

using the display keyword

The registration algorithms have a display keyword argument, that can be set to true to output figures showing the flow_est at each iteration and print some extra debug info.

method = sparse_pflap
timer = TimerOutput("ALG: " * string(method))
method_kwargs = Dict(:display => true, :timer => timer, :match_source_histogram => false)
method_args = []
flow_est, source_reg, timer, results, (figs,) = test_registration_alg(method,
                                                                      img,
                                                                      imgw,
                                                                      flow,
                                                                      timer=timer,
                                                                      method_args=method_args,
                                                                      only_flow_compare=false, # this adds source reg tests.
                                                                      method_kwargs=method_kwargs);
ind count: 297
###################
ITERATION: 1
filter_half_size: 64
inner loop iter: 1
	current inds: 69
	non NaN new estim flow vector count: 69
###################
ITERATION: 2
filter_half_size: 32
inner loop iter: 1
	current inds: 157
	non NaN new estim flow vector count: 157
###################
ITERATION: 3
filter_half_size: 16
inner loop iter: 1
	current inds: 210
	non NaN new estim flow vector count: 210
###################
ITERATION: 4
filter_half_size: 8
inner loop iter: 1
	current inds: 243
	non NaN new estim flow vector count: 243
###################
ITERATION: 5
filter_half_size: 4
inner loop iter: 1
	current inds: 256
	non NaN new estim flow vector count: 256
###################
ITERATION: 6
filter_half_size: 2
inner loop iter: 1
	current inds: 272
	non NaN new estim flow vector count: 268
###################
ITERATION: 7
filter_half_size: 1
inner loop iter: 1
	current inds: 282
	non NaN new estim flow vector count: 245
 ──────────────────────────────────────────────────────────────────────────────
                                       Time                   Allocations
                               ──────────────────────   ───────────────────────
       Tot / % measured:            1.26s / 99.0%            406MiB / 98.5%

 Section               ncalls     time   %tot     avg     alloc   %tot      avg
 ──────────────────────────────────────────────────────────────────────────────
 ALG: sparse_pflap          1    1.25s   100%   1.25s    400MiB  100%    400MiB
   single filter py...      7    1.23s  98.7%   176ms    394MiB  98.5%  56.2MiB
     single lap at ...      7    284ms  22.8%  40.6ms    121MiB  30.4%  17.4MiB
       filtering            7    257ms  20.6%  36.7ms   68.2MiB  17.1%  9.75MiB
       prepare A and b      7   26.8ms  2.15%  3.83ms   41.7MiB  10.4%  5.95MiB
         window sum...     21   15.8ms  1.27%   752μs   25.0MiB  6.26%  1.19MiB
         window sum...     14   11.0ms  0.88%   786μs   16.6MiB  4.16%  1.19MiB
       multi mat div        7    132μs  0.01%  18.8μs    298KiB  0.07%  42.5KiB
       calculate flow       7   26.4μs  0.00%  3.77μs   49.9KiB  0.01%  7.13KiB
     image interpol...      7   30.4ms  2.44%  4.34ms   21.0MiB  5.25%  3.00MiB
     flow interpola...      7   16.1ms  1.29%  2.30ms   11.7MiB  2.93%  1.67MiB
     filter inds            7    266μs  0.02%  38.1μs    245KiB  0.06%  35.0KiB
   setup                    1   16.0ms  1.28%  16.0ms   6.13MiB  1.53%  6.13MiB
     find edge points       1   15.2ms  1.22%  15.2ms   4.13MiB  1.03%  4.13MiB
 ──────────────────────────────────────────────────────────────────────────────
  mse            | 0.001
  rmse           | 0.023
  time           | 1.246
  ncc            | 0.993
  flow_mae       | 0.144
  angle-rmse     | 30.816
  angle-mae      | 4.322
  mae            | 0.012
  flow_rmse      | 0.032

This page was generated using Literate.jl.