in reply to Abstract image registration or feature detection [UPDATED w examples]
It turns out that PDL has a set of routines for precisely this task: fitwarp2d, applywarp2d.
#!/usr/bin/perl use Modern::Perl '2020'; use PDL; use PDL::Image2D; my @red_in_x; my @red_out_x; my @blue_in_x; my @blue_out_x; my @red_in_y; my @red_out_y; my @blue_in_y; my @blue_out_y; die "Usage: $0 REFERENCE TARGET" unless @ARGV >= 2; open my $F1, '<', $ARGV[0] or die "Can't open $ARGV[0]"; while (<$F1>) { chomp; next if /^$/; my @F = split; if ($F[2] =~ /p\d\d/) { push @red_in_x, $F[0]; push @red_in_y, $F[1]; } elsif ($F[2] =~ /q\d\d/) { push @blue_in_x, $F[0]; push @blue_in_y, $F[1]; } } close $F1; open my $F2, '<', $ARGV[1] or die "Can't open $ARGV[1]"; while (<$F2>) { chomp; next if /^$/; my @F = split; if ($F[2] =~ /p\d\d/) { push @red_out_x, $F[0]; push @red_out_y, $F[1]; } elsif ($F[2] =~ /q\d\d/) { push @blue_out_x, $F[0]; push @blue_out_y, $F[1]; } } close $F2; my $red_in_x = pdl @red_in_x; my $red_out_x = pdl @red_out_x; my $blue_in_x = pdl @blue_in_x; my $blue_out_x = pdl @blue_out_x; my $red_in_y = pdl @red_in_y; my $red_out_y = pdl @red_out_y; my $blue_in_y = pdl @blue_in_y; my $blue_out_y = pdl @blue_out_y; say for $red_in_x, $red_in_y, $red_out_x, $red_out_y; my ($px, $py) = fitwarp2d($red_in_x, $red_in_y, $red_out_x, $red_out_y +, 2); my ($blue_new_x, $blue_new_y) = applywarp2d($px, $py, $blue_out_x, $bl +ue_out_y); say for $blue_in_x, $blue_in_y, $blue_new_x, $blue_new_y, $blue_in_x - + $blue_new_x, $blue_in_y - $blue_new_y;
The results are not that great, but it works out of the box.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Abstract image registration or feature detection [UPDATED w examples]
by tybalt89 (Monsignor) on Jul 05, 2022 at 18:30 UTC | |
by kikuchiyo (Hermit) on Jul 06, 2022 at 12:18 UTC |