Image-DominantColors
view release on metacpan or search on metacpan
lib/Image/ColorCollection.pm view on Meta::CPAN
272829303132333435363738394041424344454647#store the centroid here..
#store belongstome
sub
getCentroid {
my
$class
=
shift
;
return
$class
->{centroid};
}
sub
addColor {
my
(
$class
,
$c
) =
@_
;
push
@{
$class
->{colors}},
$c
;
}
sub
updateCentroid {
my
(
$class
,
$c
) =
@_
;
my
$shift
= 0;
my
@colors
= @{
$class
->{colors}};
if
(
scalar
(
@colors
) == 0)
{
return
0;
}
my
$rAvg
=
int
(sum(
map
{
$_
->{r}}
@colors
)/
@colors
);
$shift
+=
$class
->{centroid}->{r} -
$rAvg
;
( run in 1.130 second using v1.01-cache-2.11-cpan-49f99fa48dc )