CSC151.01 2014F, Class 15: Transforming Images
==============================================

_Overview_

* Preliminaries.
    * Admin.
    * Upcoming Work.
    * Extra Credit.
    * Questions (Exam/Admin).
* Review of Key Ideas.
* Topic Prep.
* Lab.

Preliminaries
-------------

### Admin

* Continue lab partners.
* No Sam tomorrow.  Prof. Weinman will run class.
* Office hours: Thu/Fri 1:45-3:15; Also walking hours 1:15-1:45.
* I've started a short reference on 
  [error messages](../reference/error-messages.html).  Please feel
  free to pass along some you get.
* Two important recent comments from students.
    * "I realized that it would be much easier to do the test and study
       for quizzes if I took notes along the way."
         * Evidence (research): Taking notes helps you learn, even if
           you never read them again.
         * Sam belives that the total time is less if you take notes.
    * "In high school, I did homework at night (or in the early morning).
       I learned that I'm much better off doing homework in my open slots
       during the day, rather than waiting until night time."
* Other notes on quizzes
    * "Quiz anxiety"
    * Length

### Upcoming Work

* Lab writeup: Exercises 4a, 5b, and 5e <http://bit.ly/151-2014F-w15>
  Due Friday.
* [Exam 1](../assignments/exam.01.html) due tonight.
    * Bring printed copies on Wednesday.
* Reading for Wednesday:
    * [Making and Manipulating Homogeneous Lists](../readings/homogeneous-lists-reading.html)

### Extra Credit Opportunities

#### Academic

* Convocation Wednesday: Tara Zahra on Emigration from Eastern Europe
* CS Extras Thursday at 4:30: Mathematical Image Synthesis Toolkit (MIST)
* CS Table Friday at noon: ???
* Campus Town Hall September 30

#### Peer Support

* Noteworthy, Sat., Sept. 27, 3:30 p.m. Herrick
* Science poster session, Sat., Sept. 27, morningish, science elbow
* Football Games (Saturday, Sept. 27, at 1pm)
* Men's Tennis (???)
* Women's Tennis (???)
* Swimming (???)
* Anna Christie, Oct. 9-12 (SB plays Marthy)
* Evan's radio show 5pm Friday nights on KDIC
* Donna's radio show Sunday midnight on KDIC

#### Miscellaneous

* Participate in #GrinWell. 
  <http://www.grinnell.edu/forms/sign-grinwell-presidents-wellness-challenge>
* Friends of Drake Library needs help setting up for their annual booksale
  on Thursday, October 2 (conveniently, the same night as Grinnell High
  School's homecoming parade).  You can help a good cause and probably get
  a few free books, too.
    * Followup: They can also use help on Wednesday, October 1.

### Questions on the Exam

_There are some cases in the Quincunx problem in which the center seems
to have a non-integer coordinate.  What should I do in such cases?_

> Read the email.

> Summary: At least two choices.  You can refuse to compute.  You can 
  use a nearby pixel.  Your documentation MUST specify which you've chosen.

_Can you show a sample test for `numerator-sum-fraction-reduced`?_

> Yes.

        (define nsfr-tests
          (test-suite
           "Tests of numerator-sum-fraction-reduced"
           (test-case
            "1/2 plus 1/2"
            (check-= (numerator-sum-fraction-reduced 1 2 1 2) 1 0))
           (test-case
            "1/3 plus 1/2"
            (check-= (numerator-sum-fraction-reduced 1 3 1 2) 5 0))))a

_How many tests is enough for that test suite?_

> Enough that you feel confident that a procedure that passes your tests
  is almost certainly correct.

> About a dozen, provided they explore different potential challenges.
  E.g., just asking 1/2+1/3, 1/3+1/4, 1/4+1/5, .... doesn't really challenge
  the procedure in different ways.

_Do we have to use the generalized approach that you used for problem 4, or 
can we just work with particular values._

> I'm fine if you just work with particular values.

_How carefully should I write my postconditions for problem 1?_

> Carefully enough that someone who wants to be lazy and just meet
  the postconditions will still have to achieve the goals of the
  procedure.

> Please try to use "math" or Scheme rather than English to specify
  the postconditions.

> You may have to refer to the results of the other procedures (but
  I think we noted that).

_Can I define a procedure that takes an image and another value as input?_

> Yes.

        (define nt
          (lambda (value image)
            COMPUTATION))

        (define uniform-pixel
        (lambda (n image)
        (image-set-pixel! image n n "red")))

_Can you show me how to log in to MathLAN from my computer?_

> Yes, but not today.

Review of Key Ideas
-------------------

* (image-variant image FUN) and (image-transform! image FUN)
     * One is pure, one has side effects.
* We can combine existing functions into new functions by using 
  `compose` and `o`
     * (define rg (o irgb-redder irgb-greener))
     * Works right-to-left 
     * Note: We are defining procedures without lambda
* You can use lambda outside of a procedure definition, when you
  want a procedure but don't want to bother naming it.
     * (image-variant kitten (lambda (color) (irgb (+ 45 (irgb-red color))
                                             128
                                             0)))

Topic Prep
----------

Preliminary Questions

_Can you only compose two procedures if they take the same parameters?_

> It's a bit more complicated than that.  You can only compose two
  procedures if the output of one can serve as the input to the next.
  For example, since `image-load` takes a string and returns an image,
  and `image-show` takes an image (and returns an image), we can 
  write `(compose image-show image-load)`, but not the other way
  around.

> Right now, we will primarily compose functions that take the same
  kind of input and have the same kind of output, such as color
  transformations.

_Can we return multiple value?_

> After tomorrow.

Followup Questions

Talk to your partner: What, if anything, was confusing about the reading?  
(Feel free to post to the question board.)

Followup Questions

_Can you explain the following?_

        (image-variant kitten (lambda (color) (irgb (irgb-red color) 0 0)))

_How can the computer use the lambda expressions?_

        (image-variant kitten (lambda (color) (irgb (irgb-red color) 0 0)))

_Why does the image-variant work even though you haven't provided an input?_

        (image-variant kitten irgb-redder)

_Can I use the composition operator with math functions?_

> Yes

        (define qad (o square square))

_Can I use the composition operator to write something that returns f^n(x)?_

> Yes, eventually.

Lab
---

Three approaches I've seen to undoing irgb-redder, at least for most values

    (define anti-redder (o irgb-darker irgb-darker irgb-greener irgb-bluer))

    (define anti-redder (o irgb-complement irgb-redder irgb-complement))

    (define anti-redder (lambda (color) (irgb (- (irgb-red color) 16)
                                              (irgb-green color)
                                              (irgb-blue color))))
