Task as stated looks pretty much as case for interpolation to me. One trick pony, etc., but I even found my answer (Re: which function in PDL can do the same thing as matlab pcolor?) through SS for "Delaunay", see links in last paragraph there, especially ugly formulae for barycentric weights (didn't find ready-made solution on CPAN). Code is adjusted version of what I did a few years ago for some image hacking, unrelated to feature recognition.

No idea what data pryrt used for a sample (same "red-blue" terms used here), and whether they are supposed to represent a trivial demo, or, indeed, an "interesting" non-affine distortion was applied. Anyway, results below seem to match well with his, even if it's just a hack -- X and Y of target are treated as separate functions to interpolate, with, furthermore, simple linear interpolation.

use strict; use warnings; use feature qw/ say /; use POSIX qw/ round /; # use 5.022; use List::Util qw/ sum /; use Math::Geometry::Delaunay qw/ TRI_CONSTRAINED /; use constant EPSILON_NEGATIVE => -1e-6; sub key { pack 'II', @{ $_[ 0 ]}} my @red_in = ( [58,48], [108,155], [186,80], [255,191], [331,48] ); my @red_out = ( [471,15], [531,141], [603,90], [682,227], [747,107] ); my %mapped = map { key( $red_in[ $_ ]), $red_out[ $_ ]} 0 .. $#red_in +; my $tri = Math::Geometry::Delaunay-> new( TRI_CONSTRAINED ); $tri-> addPoints( \@red_in ); $tri-> triangulate; my @blue_in = ( [125,73], [197,158], [282,94] ); BLUE: for my $blue ( @blue_in ) { TRI: for my $elem ( @{ $tri-> elements }) { my $y23 = $elem-> [ 1 ][ 1 ] - $elem-> [ 2 ][ 1 ]; my $x32 = $elem-> [ 2 ][ 0 ] - $elem-> [ 1 ][ 0 ]; my $x13 = $elem-> [ 0 ][ 0 ] - $elem-> [ 2 ][ 0 ]; my $y13 = $elem-> [ 0 ][ 1 ] - $elem-> [ 2 ][ 1 ]; my $denominator = $y23 * $x13 + $x32 * $y13; my $xx3 = $blue-> [ 0 ] - $elem-> [ 2 ][ 0 ]; my $yy3 = $blue-> [ 1 ] - $elem-> [ 2 ][ 1 ]; my @weights; next TRI if EPSILON_NEGATIVE > ( $weights[ 0 ] = ( $y23 * $xx3 + $x32 * $yy3 ) / $denominator ); next TRI if EPSILON_NEGATIVE > ( $weights[ 1 ] = ( -$y13 * $xx3 + $x13 * $yy3 ) / $denominator ); next TRI if EPSILON_NEGATIVE > ( $weights[ 2 ] = 1 - $weights[ 0 ] - $weights[ 1 ]); printf "[%3d,%3d] => [%3d,%3d]\n", @$blue, map { my $coord = $_; round sum map { $weights[ $_ ] * $mapped{ key $elem-> [ $_ ]}[ $co +ord ] } 0 .. 2 # 3 vertices } 0, 1; # x, y next BLUE } die "point @$blue outside convex hull" } __END__ [125, 73] => [541, 63] [197,158] => [621,174] [282, 94] => [701,137]

In reply to Re: Abstract image registration or feature detection by vr
in thread Abstract image registration or feature detection [UPDATED w examples] by kikuchiyo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.