Color-RGB-Util

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

         ( (R1-R2)**2 + (G1-G2)**2 + (B1-B2)**2 )**0.5

        which is the same as what "rgb_distance"() would produce.

    *   approx1

        This algorithm, described in [1] as "a low cost approximation" and
        "a combination both weighted Euclidean distance functions, where the
        weight factors depend on how big the 'red' component of the colour
        is" with "results that are very close to L*u*v" and "a more stable
        algorithm", uses the following formula:

         ( 2*(R1-R2)**2 + 4*(G1-G2)**2 + 3*(B1-B2)**2 + Rm*((R1-R2)**2 - (B1-B2)**2)/256 )**0.5

        where, Rm or "R mean" is (R1+R2)/2.

    *   approx2

        Like "approx1", but uses this formula:

         ( 2*(R1-R2)**2 + 4*(G1-G2)**2 + 3*(B1-B2)**2 )**0.5  # if Rm < 128
         ( 3*(R1-R2)**2 + 4*(G1-G2)**2 + 2*(B1-B2)**2 )**0.5  # otherwise

    *   hsv_euclidean

        Convert the RGB values to HSV, then calculate the HSV distance.
        Please see source code for details.

    *   hsv_hue1

README  view on Meta::CPAN


    [1] https://www.compuphase.com/cmetric.htm

    See also rgb_distance.

  rgb_distance
    Usage:

     my $dist = rgb_distance($rgb1, $rgb2)

    Calculate the euclidean RGB distance, using this formula:

     ( (R1-R2)**2 + (G1-G2)**2 + (B1-B2)**2 )**0.5

    For example, the distance between "000000" and "ffffff" is ~441.67,
    while the distance between "ffff00" and "ffffff" is 255.

    See also rgb_diff.

  rgb_is_dark
    Usage:

README  view on Meta::CPAN

    if the RGB distance to "000000" is larger than to "ffffff".

    See also "rgb_is_dark".

  rgb_luminance
    Usage:

     my $luminance = rgb_luminance($rgb);

    Calculate standard/objective luminance from RGB value using this
    formula:

     (0.2126*R) + (0.7152*G) + (0.0722*B)

    where R, G, and B range from 0 to 1. Return a number from 0 to 1.

  tint_rgb_color
    Usage:

     my $new_rgb = tint_rgb_color($rgb, $tint_rgb, $pct)

lib/Color/RGB/Util.pm  view on Meta::CPAN


 ( (R1-R2)**2 + (G1-G2)**2 + (B1-B2)**2 )**0.5

which is the same as what L</"rgb_distance">() would produce.

=item * approx1

This algorithm, described in [1] as "a low cost approximation" and "a
combination both weighted Euclidean distance functions, where the weight factors
depend on how big the 'red' component of the colour is" with "results that are
very close to L*u*v" and "a more stable algorithm", uses the following formula:

 ( 2*(R1-R2)**2 + 4*(G1-G2)**2 + 3*(B1-B2)**2 + Rm*((R1-R2)**2 - (B1-B2)**2)/256 )**0.5

where, Rm or "R mean" is (R1+R2)/2.

=item * approx2

Like C<approx1>, but uses this formula:

 ( 2*(R1-R2)**2 + 4*(G1-G2)**2 + 3*(B1-B2)**2 )**0.5  # if Rm < 128
 ( 3*(R1-R2)**2 + 4*(G1-G2)**2 + 2*(B1-B2)**2 )**0.5  # otherwise

=item * hsv_euclidean

Convert the RGB values to HSV, then calculate the HSV distance. Please see
source code for details.

=item * hsv_hue1

lib/Color/RGB/Util.pm  view on Meta::CPAN

[1] https://www.compuphase.com/cmetric.htm

See also L<rgb_distance>.

=head2 rgb_distance

Usage:

 my $dist = rgb_distance($rgb1, $rgb2)

Calculate the euclidean RGB distance, using this formula:

 ( (R1-R2)**2 + (G1-G2)**2 + (B1-B2)**2 )**0.5

For example, the distance between "000000" and "ffffff" is ~441.67, while the
distance between "ffff00" and "ffffff" is 255.

See also L<rgb_diff>.

=head2 rgb_is_dark

lib/Color/RGB/Util.pm  view on Meta::CPAN

the RGB distance to "000000" is larger than to "ffffff".

See also L</rgb_is_dark>.

=head2 rgb_luminance

Usage:

 my $luminance = rgb_luminance($rgb);

Calculate standard/objective luminance from RGB value using this formula:

 (0.2126*R) + (0.7152*G) + (0.0722*B)

where R, G, and B range from 0 to 1. Return a number from 0 to 1.

=head2 tint_rgb_color

Usage:

 my $new_rgb = tint_rgb_color($rgb, $tint_rgb, $pct)



( run in 1.641 second using v1.01-cache-2.11-cpan-df04353d9ac )