Thursday, 4 April 2013

The Contrast

I finally finished my project 2 and I was so happy. I remembered there were some challenges I faced when I did the contrast, for example, what did the key "z" do? or how to run it?

First, I tried to understand what changes I need to make and what should be fixed in this project. Then, I looked the whole programming over very carefully and I knew how the contrast works: it requires you to increase the contrast of the red, green, blue portion of the image blinky by pressing different keys. If you press "r", it will increase the contrast the red color of blinky. If you press "g", it will increase the contrast of green color of blinky. By increasing the contrast, you should define "sharpen-r","sharpen-g"and "sharpen-b".some definition of them is wrong and what I need to do is to fix the definition. some have the right definition but do not have check expect and I need to add some check-expect. Also, write the key-press to let it run by pressing these keys.

As you can see below, Sharpen-r just changes color-red and keeps other color the same. For the change, 
it compares color-red with 128, if it is less than 128, then times 7 of the color-red and plus 0, but if it is greater than 128, then times 7 color-red and plus 255. After that, divide 8.
(define (sharpen-r c)
  (make-color
   (quotient (+ (* 7 (color-red c))
                (cond [(< (color-red c) 128) 0] [else 255])) 8)
   (color-green c) (color-blue c) (color-alpha c)))
By imitating, I just changed sharpen-r to sharpen-g and put color-red in the first position, then the sharpen-g of color-green, following color-blue and color-alpha.
Check-expect is the same idea, so I just changed the order and the name of the contrast color.
In terms of key-press, it is complicated, but if I write a right definition for one key-press, then the others would be the same idea. For example, there is a check-expect of pressing "r"
(check-expect (toggle (make-imgpair blinky blinky) "r")
              (make-imgpair blinky (map-image sharpen-r blinky)))
 I found it just increased the contrast of red portion of "imgpair after" and the "imgpair before" was still the original blinky. so according to the check-expect, I could get the definition: 
[(equal? k "r") (map-image sharpen-r (imgpair-after ip))]

I ran the system, but one test about pressing "z" failed. Then I looked it back. I found that "z" is to restore the image, which means if you press "z", it should be the same image as before. Then I fixed it and finally all my tests passed.


No comments:

Post a Comment