15110 SUMMER SESSION ONE - 2013

Lab 10 - Tuesday, June 18

CA Demonstration

  1. remove_red!(b)

  2. functions in ppm.rb

  3. unix command:

    display filename
    

Files

  1. ppm.rb
  2. nautical.ppm

Deliverables

  1. remove_red.rb
  2. happy_face.rb
  3. remove_green.rb
  4. dim.rb
  5. big_face.rb

Activities

  1. Create a function happy_face() that returns a 3D Rubby array containing the bitmap image of the \(5\text{ pixel}\times 4\text{ pixel}\) smiling face shown below.

    Example Usage:

    >> plot(happy_face(),20)
    

    Note: The eyes are "midnight blue", the lips are "crimson", and the nose is black". (See RGB Color Table)

  2. Create a function remove_green!(image) that alters image so that none of the pixels have any green remaining in them but they each still have the same red and blue values.

    Example:

    >> b = load_ppm("nautical.ppm"); nil
    => nil
    >> plot(b)
    => nil
    >> remove_green!(b)
    => nil
    >> plot(b)
    => nil
    
    becomes
  3. Create a function dim!(image) that alters image so that each pixel is an \(\frac{1}{3}\) as bright as in the original image. Each pixel should also keep the same proportion of red, green, blue (subject to rounding errors).

    Possible algorithm: For each row in the image and each column in that row:

    1. Set the red component of the pixel array at that row and column in the image to one-third of its old value rounded down to a whole number.
    2. Set the green component of the pixel array at that row and column in the image to one-third of its old value rounded down to a whole number.
    3. Set the blue component of the pixel array at that row and column in the image to one-third of its old value rounded down to a whole number.

    Example:

    >> b = load_ppm("nautical.ppm"); nil
    => nil
    >> plot(b)
    => nil
    >> dim!(b)
    => nil
    >> plot(b)
    => nil
    
    becomes
  4. Challenge: Create a function big_face() that returns a 3d bitmap array for a 300x300 face as shown in the following figure:

    Example:

    >> plot(big_face())
    => nil