Class RGBColor

  • All Implemented Interfaces:
    RGBIndex

    public class RGBColor
    extends Object
    implements RGBIndex
    Encapsulates a single color from RGB (red, green, blue) color space plus a frequency counter. Each of the three RGB samples is of type int. Also stores a counter of type int.
    Author:
    Marco Schmidt
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int counter
      Stores how many times this colors appears in a certain image.
      private int[] samples
      The intensity values that make up the color.
    • Constructor Summary

      Constructors 
      Constructor Description
      RGBColor​(int red, int green, int blue)
      Creates an instance of this class and initializes it to the given intensity values.
      RGBColor​(int red, int green, int blue, int counter)
      Creates an instance of this class and initializes it to the given intensity values.
    • Field Detail

      • samples

        private int[] samples
        The intensity values that make up the color.
      • counter

        private int counter
        Stores how many times this colors appears in a certain image.
    • Constructor Detail

      • RGBColor

        public RGBColor​(int red,
                        int green,
                        int blue)
        Creates an instance of this class and initializes it to the given intensity values. The internal color counter is set to zero.
      • RGBColor

        public RGBColor​(int red,
                        int green,
                        int blue,
                        int counter)
        Creates an instance of this class and initializes it to the given intensity values. Also sets the internal color counter to the given parameter.
    • Method Detail

      • compareTo

        public int compareTo​(RGBColor c,
                             int sortOrder)
        Compares this color to the argument color, using the sortOrder argument (which is one of the three index values defined in RGBIndex. That way, the two sample values for one component (e.g. red if sortOrder == INDEX_RED) are compared.
        Parameters:
        c - the color to which this color is compared
        sortOrder - the component used for the comparison
        Returns:
        relation between this color and the argument color
      • computeDistance

        public static double computeDistance​(int r1,
                                             int g1,
                                             int b1,
                                             int r2,
                                             int g2,
                                             int b2)
        For two RGB triplets (r1, g1, b1) and (r2, g2, b2) this will return the distance between those colors in RGB color space.
      • equals

        public boolean equals​(Object obj)
        Compares this color with another instance of RGBColor and returns true if all intensity values are equal, false otherwise.
        Overrides:
        equals in class Object
      • getCounter

        public int getCounter()
      • getSample

        public int getSample​(int index)