Experimental Image::BoxFind module: Image/t/11-looks_like_edge.t
# Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
# doom@kzsu.stanford.edu 2007/10/22 04:50:12
use warnings;
use strict;
$|=1;
my $DEBUG = 1; # TODO set to 0 before ship
use Data::Dumper;
use Test::More;
BEGIN { plan tests => 14 };
use Data::Dumper;
use File::Basename qw( basename );
use FindBin qw( $Bin );
use lib "$Bin/../..";
BEGIN { #1
use_ok( 'Image::BoxFind' );
}
#2
ok(1, "Traditional: If we made it this far, we're ok.");
my @edge_pixpats;
push @edge_pixpats,
[
'65535,65535,65535,0',
'65535,65535,65535,0',
'52000,61937,54313,0',
'45232,60138,48702,0'
];
push @edge_pixpats,
[
'61423,61423,61423,0',
'44204,51914,58724,0',
'34352,44375,53199,0',
'42148,49665,56283,0',
'46825,52839,58133,0',
'49944,54955,59367,0',
'52171,56467,60248,0',
'53842,57600,60909,0'
];
push @edge_pixpats,
[
'61423,61423,61423,0',
'49858,49858,49858,0',
'54570,54570,54570,0',
'56861,56861,56861,0',
'58185,58185,58185,0',
'59024,59024,59024,0',
'59587,59587,59587,0',
'59977,59913,59881,0'
];
push @edge_pixpats,
[
'61423,61423,61423,0',
'26985,42405,56026,0',
'14649,29298,42148,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'19275,19275,19275,0',
'32296,32296,32296,0'
];
push @edge_pixpats,
[
'61423,61423,61423,0',
'26985,42405,56026,0',
'14649,29298,42148,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'4883,4883,4883,0',
'44718,44718,44718,0'
];
push @edge_pixpats,
[
'61423,61423,61423,0',
'26985,42406,56026,0',
'14649,29298,42148,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'7196,7196,7196,0',
'43176,43176,43176,0'
];
my @not_edge_pixpats;
push @not_edge_pixpats,
[
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
'65535,65535,65535,0',
];
push @not_edge_pixpats,
[
'14649,29298,42148,0',
'14649,29298,42148,0',
'14649,29298,42148,0',
'14649,29298,42148,0',
'14649,29298,42148,0',
'14649,29298,42148,0',
];
push @not_edge_pixpats,
[
'14649,29298,42148,0',
'14652,29298,42148,0',
'14654,29298,42148,0',
'14658,29298,42148,0',
'14660,29298,42148,0',
'14662,29298,42148,0',
];
push @not_edge_pixpats,
[
'14649,29298,42148,0',
'14652,29300,42148,0',
'14654,29305,42148,0',
'14658,29310,42148,0',
'14660,29315,42148,0',
'14662,29320,42148,0',
];
push @not_edge_pixpats,
[
'14649,29298,42148,0',
'14652,29300,42155,0',
'14654,29305,42165,0',
'14658,29310,42175,0',
'14660,29315,42185,0',
'14662,29320,42195,0',
];
push @not_edge_pixpats,
[
'14649,29298,42148,0',
'14652,29305,42155,0',
'14654,29315,42165,0',
'14658,29325,42175,0',
'14660,29335,42185,0',
'14662,29345,42195,0',
];
{
my $test_name = "looks_like_edge";
my $bf = Image::BoxFind->new( { DEBUG => $DEBUG,
} );
$bf->set_edge_contrast_cutoff( 10 );
my $expected = 1;
foreach my $pixpat (@edge_pixpats) {
my $result = $bf->looks_like_edge( $pixpat );
is( $result, $expected, "Testing $test_name" ) or
print STDERR "Unexpected fail:". Dumper( $pixpat ). "\n";
}
}
{
my $test_name = "does NOT looks_like_edge";
my $bf = Image::BoxFind->new( { DEBUG => $DEBUG,
} );
$bf->set_edge_contrast_cutoff( 10 );
my $expected = '';
foreach my $pixpat (@not_edge_pixpats) {
my $result = $bf->looks_like_edge( $pixpat );
is( $result, $expected, "Testing $test_name" ) or
print STDERR "Unexpected pass:". Dumper( $pixpat ). "\n";
}
}
exit;
# The following were experiments to see how it behaves with
# a low cutoff of only 2. Answer: still identifies all the real
# edges, but also passes one of my negative cases.
{
my $test_name = "looks_like_edge LOW CUTOFF";
my $bf = Image::BoxFind->new( { DEBUG => $DEBUG,
} );
$bf->set_edge_contrast_cutoff( 2 );
my $expected = 1;
foreach my $pixpat (@edge_pixpats) {
my $result = $bf->looks_like_edge( $pixpat );
is( $result, $expected, "Testing $test_name" ) or
print STDERR "Unexpected fail:". Dumper( $pixpat ). "\n";
}
}
{
my $test_name = "does NOT looks_like_edge LOW CUTOFF";
my $bf = Image::BoxFind->new( { DEBUG => $DEBUG,
} );
$bf->set_edge_contrast_cutoff( 2 );
my $expected = '';
foreach my $pixpat (@not_edge_pixpats) {
my $result = $bf->looks_like_edge( $pixpat );
is( $result, $expected, "Testing $test_name" ) or
print STDERR "Unexpected pass:". Dumper( $pixpat ). "\n";
}
}
Joseph Brenner,
Tue Nov 27 17:40:02 2007