| 1 | # Comparator for the "average threshold" comparison method. | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package Image::Compare::AVG_THRESHOLD; | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | ▶ | use constant MEAN => 0; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use constant MEDIAN => 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | ▶ | use base qw/Image::Compare::Comparator/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | sub accumulate { | ||||||||||||||
| 14 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
accumulate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 15 | 0 | my $diff = $self->color_distance(@_); | |||||||||||||
| 16 | 0 | ▶ | if ($self->{args}{type} == &MEAN) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | 0 | $self->{count}++; | |||||||||||||
| 18 | 0 | $self->{sum} += $diff; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | elsif ($self->{args}{type} == &MEDIAN) { | ||||||||||||||
| 21 | 0 | push(@{$self->{scores}}, $diff); | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | else { | ||||||||||||||
| 24 | 0 | die "Unrecognized average type: '$self->{args}{type}'"; | |||||||||||||
| 25 | } | ||||||||||||||
| 26 | 0 | return undef; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | sub get_result { | ||||||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
get_result: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 31 | 0 | my $val = 0; | |||||||||||||
| 32 | 0 | ▶ | if ($self->{args}{type} == &MEAN) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 33 | 0 | $val = $self->{sum} / $self->{count}; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | elsif ($self->{args}{type} == &MEDIAN) { | ||||||||||||||
| 36 | 0 | my @vals = sort @{$self->{scores}}; | |||||||||||||
| 37 | 0 | ▶ | if (@vals % 2) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | # Return the middle value | ||||||||||||||
| 39 | 0 | $val = $vals[(@vals / 2)]; | |||||||||||||
| 40 | } | ||||||||||||||
| 41 | else { | ||||||||||||||
| 42 | # Return the mean of the middle two values | ||||||||||||||
| 43 | 0 | $val = $vals[ @vals / 2 ]; | |||||||||||||
| 44 | 0 | $val += $vals[(@vals / 2) - 1]; | |||||||||||||
| 45 | 0 | $val /= 2; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | } | ||||||||||||||
| 48 | 0 | return $val <= $self->{args}{value}; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 1 | 1; | |||||||||||||
| 52 | |||||||||||||||
| 53 | __END__ | ||||||||||||||