{"action":"created","issue":{"url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/5","repository_url":"https://api.github.com/repos/estrabd/Image-Libpuzzle","labels_url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/5/comments","events_url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/5/events","html_url":"https://github.com/estrabd/Image-Libpuzzle/issues/5","id":133846968,"number":5,"title":"vector_normalized_distance varies depending on size of image","user":{"login":"benkasminbullock","id":102005,"avatar_url":"https://avatars.githubusercontent.com/u/102005?v=3","gravatar_id":"","url":"https://api.github.com/users/benkasminbullock","html_url":"https://github.com/benkasminbullock","followers_url":"https://api.github.com/users/benkasminbullock/followers","following_url":"https://api.github.com/users/benkasminbullock/following{/other_user}","gists_url":"https://api.github.com/users/benkasminbullock/gists{/gist_id}","starred_url":"https://api.github.com/users/benkasminbullock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benkasminbullock/subscriptions","organizations_url":"https://api.github.com/users/benkasminbullock/orgs","repos_url":"https://api.github.com/users/benkasminbullock/repos","events_url":"https://api.github.com/users/benkasminbullock/events{/privacy}","received_events_url":"https://api.github.com/users/benkasminbullock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-16T00:04:05Z","updated_at":"2016-02-16T06:37:12Z","closed_at":null,"body":"Using the following image:\r\n\r\nhttp://xtremewalls.com/supermodels/Lena_Gercke/lena-gercke-001-01.jpg\r\n\r\nI made various sized versions using Imager:\r\n\r\n    #!/home/ben/software/install/bin/perl\r\n    use warnings;\r\n    use strict;\r\n    use utf8;\r\n    use Imager;\r\n    my $photo = 'lena-gercke-001-01.jpg';\r\n    my $img = Imager->new ();\r\n    $img->read (file => $photo) or die $img->errstr ();\r\n    for my $s (1..10) {\r\n        my $size = 100*$s;\r\n        my $out = $img->scale (xpixels => $size, ypixels => $size);\r\n        $out->write (file => \"lena-$size.png\") or die $out->errstr ();\r\n    }\r\n\r\nThen I tried running Image::Libpuzzle against the original and smaller images:\r\n\r\n    #!/home/ben/software/install/bin/perl\r\n    use warnings;\r\n    use strict;\r\n    use utf8;\r\n    use FindBin '$Bin';\r\n    use Image::Libpuzzle;\r\n    my $photo = 'lena-gercke-001-01.jpg';\r\n    my $p1 = Image::Libpuzzle->new;\r\n    my $p2 = Image::Libpuzzle->new;\r\n    my $sig1 = $p1->fill_cvec_from_file ($photo);\r\n    my $s1 = $p1->signature_as_hex_string ();\r\n    for my $s (1..10) {\r\n        my $size =$s*100;\r\n        my $photo2 = \"$Bin/lena-$size.png\";\r\n        my $sig2 = $p2->fill_cvec_from_file ($photo2);\r\n        print \"$size: \", $p1->vector_normalized_distance ($p2), \"\\n\";\r\n    }\r\n\r\nThe outputs look like this:\r\n<pre>\r\n100: 0.631680045723442\r\n200: 0.616250444274758\r\n300: 0.0698092831405639\r\n400: 0.604140770698438\r\n500: 0.623692779736408\r\n600: 0.037084321574116\r\n700: 0.60607610711603\r\n800: 0.622808505614176\r\n900: 0.0419672983694311\r\n1000: 0.606291586628549\r\n</pre>\r\nIt's very striking that the numbers are completely different for the sizes which are a factor of three and which are not. Did I make some kind of error here? I was also able to reproduce this using a C program with the original libpuzzle. I did some digging and found that the centres of the pixel squares seem to be wrong, which may be why this happens.\r\n\r\nI tried this on a number of different images and was able to reproduce it with most of them. Since they were private photos I couldn't use them, so I tried with a [Lenna image](https://en.wikipedia.org/wiki/Lenna). I couldn't reproduce it with a Lenna image but the above I found on a google image search for \"lena\".\r\n"},"comment":{"url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/comments/184544932","html_url":"https://github.com/estrabd/Image-Libpuzzle/issues/5#issuecomment-184544932","issue_url":"https://api.github.com/repos/estrabd/Image-Libpuzzle/issues/5","id":184544932,"user":{"login":"benkasminbullock","id":102005,"avatar_url":"https://avatars.githubusercontent.com/u/102005?v=3","gravatar_id":"","url":"https://api.github.com/users/benkasminbullock","html_url":"https://github.com/benkasminbullock","followers_url":"https://api.github.com/users/benkasminbullock/followers","following_url":"https://api.github.com/users/benkasminbullock/following{/other_user}","gists_url":"https://api.github.com/users/benkasminbullock/gists{/gist_id}","starred_url":"https://api.github.com/users/benkasminbullock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benkasminbullock/subscriptions","organizations_url":"https://api.github.com/users/benkasminbullock/orgs","repos_url":"https://api.github.com/users/benkasminbullock/repos","events_url":"https://api.github.com/users/benkasminbullock/events{/privacy}","received_events_url":"https://api.github.com/users/benkasminbullock/received_events","type":"User","site_admin":false},"created_at":"2016-02-16T06:37:12Z","updated_at":"2016-02-16T06:37:12Z","body":"Further to this, I tried making some simple graphics to see what would happen.\r\n\r\nThe following script prints simple chessboard graphics:\r\n<pre>\r\n#!/home/ben/software/install/bin/perl\r\n\r\n# Make simple images for use in testing libpuzzle\r\n\r\nuse warnings;\r\nuse strict;\r\nuse utf8;\r\nuse FindBin '$Bin';\r\nuse Cairo;\r\nmy $outdir = \"$Bin/simg\";\r\nif (! -d $outdir) {\r\n    die \"No $outdir\";\r\n}\r\n# http://www.lemoda.net/cairo/cairo-tutorial/line.html\r\nfor my $s (1..20) {\r\n    my $size = $s * 100;\r\n    my $surface = Cairo::ImageSurface->create ('rgb24', $size, $size);\r\n    my $cr = Cairo::Context->create ($surface);\r\n    $cr->rectangle (0, 0, $size/2.0, $size);\r\n    $cr->set_source_rgb (0, 0, 0);\r\n    $cr->fill ();\r\n    $cr->rectangle ($size/2.0, 0, $size, $size);\r\n    $cr->set_source_rgb (1, 1, 1);\r\n    $cr->fill ();\r\n    $surface->write_to_png (\"$outdir/bw-$size.png\");\r\n    for my $x (0..7) {\r\n\tfor my $y (0..7) {\r\n\t    my $bw = $x + $y;\r\n\t    if ($bw % 2 == 0) {\r\n\t\t$cr->set_source_rgb (1, 1, 1);\r\n\t    }\r\n\t    else {\r\n\t\t$cr->set_source_rgb (0, 0, 0);\r\n\t    }\r\n\t    $cr->rectangle ($x/8*$size, $y/8*$size,($x+1)/8*$size, ($y+1)/8*$size,);\r\n\t    $cr->fill ();\r\n\t}\r\n    }\r\n    $surface->write_to_png (\"$outdir/chess-$size.png\");\r\n}\r\n</pre>\r\nThe chessboards can be visually inspected.\r\n\r\nUsing these I adapted the above script to compare the chessboards as follows:\r\n<pre>\r\n#!/home/ben/software/install/bin/perl\r\n\r\n# Test Libpuzzle on simple images\r\n\r\nuse warnings;\r\nuse strict;\r\nuse utf8;\r\nuse FindBin '$Bin';\r\nuse Image::Libpuzzle;\r\n\r\nmy $oldsig;\r\nmy @p;\r\nfor my $s (1..20) {\r\n    my $size = $s*100;\r\n    my $photo2 = \"$Bin/simg/chess-$size.png\";\r\n    $p[$s] = Image::Libpuzzle->new ();\r\n    $p[$s]->fill_cvec_from_file ($photo2);\r\n    my $sig = $p[$s]->signature_as_hex_string ();\r\n    if ($oldsig) {\r\n\tif ($sig ne $oldsig) {\r\n\t    print \"$size: \", $p[$s]->vector_normalized_distance ($p[$s-1]), \"\\n\";\r\n\t}\r\n    }\r\n    $oldsig = $sig;\r\n}\r\n</pre>\r\nThe output I get is as follows:\r\n<pre>\r\n200: 0.297885626124051\r\n300: 0.167714483784924\r\n400: 0.0377426060986464\r\n500: 0.159963154941154\r\n600: 0.204693546582767\r\n700: 0.141560905901128\r\n800: 0.0436021508164603\r\n900: 0.158667748953097\r\n1000: 0.203797807460921\r\n1100: 0.141560905901128\r\n1200: 0.0436021508164603\r\n1300: 0.158667748953097\r\n1400: 0.197989962089072\r\n1500: 0.138564982488454\r\n1600: 0.0436021508164603\r\n1700: 0.153354519552891\r\n1800: 0.188068537824949\r\n1900: 0.135492550984666\r\n2000: 0.0436021508164603\r\n</pre>\r\nSince it's comparing identical images each time, the variation indicates something amiss.\r\n\r\n"}}