Package org.cis1200

Class SimpleManipulations

java.lang.Object
org.cis1200.SimpleManipulations

public class SimpleManipulations extends Object
  • Constructor Details

    • SimpleManipulations

      public SimpleManipulations()
  • Method Details

    • rotateCW

      public static PixelPicture rotateCW(PixelPicture pic)
      Rotate a picture 90 degrees clockwise. For example, consider this bitmap, where each pixel is labeled by its coordinates: (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) Rotating this bitmap CW will produce the following bitmap, with relabeled coordinates: (1, 0) (0, 0) (1, 1) (0, 1) (1, 2) (0, 2) This method implements this "relabeling," copying pixels from their old coordinates to their new coordinates.
      Parameters:
      pic - The original picture to rotate.
      Returns:
      The rotated picture.
    • rotateCCW

      public static PixelPicture rotateCCW(PixelPicture pic)
      Rotate a picture 90 degrees counter-clockwise. For example, consider this bitmap, where each pixel is labeled by its coordinates: (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) Rotating this bitmap CCW will produce the following bitmap, with relabeled coordinates: (0, 2) (1, 2) (0, 1) (1, 1) (0, 0) (1, 0) Your job is to implement this "relabeling," copying pixels from their old coordinates to their new coordinates.
      Parameters:
      pic - The original picture to rotate.
      Returns:
      The rotated picture.
    • border

      public static PixelPicture border(PixelPicture pic, int borderWidth, Pixel borderColor)
      Create a new image by adding a border to a specified image.
      Parameters:
      pic - the original picture
      borderWidth - number of pixels in the border
      borderColor - color of the border.
      Returns:
      a copy of the input picture with a border
    • grayScaleLuminosity

      public static PixelPicture grayScaleLuminosity(PixelPicture pic)
      Transforms a picture to its GrayScale equivalent using the luminosity algorithm. Luminosity is a weighted average that adjusts the GrayScale value based on human perception. We are more sensitive to green, so it is weighted more heavily. Different image manipulation programs use different values. We will use the one Photoshop uses: round(0.299*R + 0.587*G + 0.114*B). NOTE: round is a static method in the Math class from the Java standard library: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#round-double- Use Math.round at the very end of your calculation before casting to an int. After computing the weighted average, create a new pixel with this average as its component values. For example, the reddish color (180, 100, 80) becomes (122, 122, 122).
      Parameters:
      pic - the original picture
      Returns:
      a new picture that is the GrayScale equivalent of the original picture
    • invertColors

      public static PixelPicture invertColors(PixelPicture pic)
      Create a new image by inverting the color of each pixel. To do this, simply create a new PixelPicture where each color component of each pixel is the inverse of the original value. To invert a color component, subtract it from 255.
      Parameters:
      pic - the picture to be inverted
      Returns:
      new picture with inverted colors
    • grayScaleAverage

      public static PixelPicture grayScaleAverage(PixelPicture pic)
      Transform a colored picture to its grayscale equivalent using an averaging algorithm. To do this, simply find the average of the color components of each pixel in question, and create a new pixel with this average as its component values. For example, the reddish color (180, 100, 80) becomes (120, 120, 120). That is, the formula is (R + G + B) / 3.0 Note: / in the formula above is a double operation. Use Math.round at the very end of your calculation before casting to an int.
      Parameters:
      pic - the original picture
      Returns:
      new grayscale image
    • scaleColors

      public static PixelPicture scaleColors(PixelPicture pic, double rFactor, double gFactor, double bFactor)
      Scale the color components of a picture. To do this, simply replace each pixel with a new one where each color component is the original value multiplied by the scaling factor for that color. Note that each component of the resulting pixel must have values in the range 0 <= color <= 255. Use Math.round before converting double values to ints.
      Parameters:
      pic - original image
      rFactor - red factor
      gFactor - green factor
      bFactor - blue factor
      Returns:
      new image with scaled colors
    • weightedAverage

      public static int weightedAverage(double alpha, int x, int y)
      Compute the weighted average of two integers. If alpha is 0.5, the weightedAverage is the same as the average of the two numbers. If alpha is 1.0, then x is returned. Likewise, if it is 0.0, than the result is y.
      Parameters:
      alpha - weight
      x - first integer
      y - second integer
      Returns:
      weighted average of x and y
    • alphaBlend

      public static PixelPicture alphaBlend(double alpha, PixelPicture pic, PixelPicture f)
      Blend two pictures together by taking a weighted average of each pixel. The weighted average of two int values is given by the static method above. This transformation applies this formula to each color in the corresponding pixels of the two images. The two images must be exactly the same size for this transformation to apply. If the dimensions of the second image do not match those of the first, then the first image is returned unchanged.
      Parameters:
      alpha - weight
      pic - first picture
      f - second picture
      Returns:
      the blended image
    • vignette

      public static PixelPicture vignette(PixelPicture pic)
      Adds dark edges to an image to draw interest to the center. http://en.wikipedia.org/wiki/Vignetting We'll do this by calculating the distance from each pixel to the center of the image, and then multiplying the color values of that pixel by one minus the square of that distance. In other words, 1. Find the col,row coordinates of the center pixels of the image, cx and cy. For example, if the image has width 5 and height 3, then the center pixel is located at (2,1). We'll use doubles to represent this value, in order to account for cases where the picture has an even number of pixels. For example, if the width is 4 and the height 6, then the center is at (1.5, 2.5). 2. For each pixel in the image, find its (proportional) distance d from the center. This is the distance from the center in the col and row directions, divided by the total distance from the center to any corner. d = Math.sqrt (dx * dx + dy * dy) / Math.sqrt (cx * cx + cy * cy) 3. Compute the multiplicative factor f from the distance. This factor should be 1.0 at the center of the picture (i.e. d=0) and then decrease to 0.0 near the edges. f = 1.0 - (d * d) 4. Multiply each component of the pixel by the factor f. Use Math.round to convert the result to an integer value before casting to an int. 5. There is one special case. If the distance from the center to any corner is zero (i.e. if the picture contains a single pixel) this method should just return the original input.
      Parameters:
      pic - original image
      Returns:
      new image with with dark edges