Summary: In this laboratory, you will extend the operations you’ve used to transform colors into operations that transform images.
Reference:
(image-variant image fun) MediaScheme GIMP Procedure.image, each of whose pixels is computed by applying fun to the color of the corresponding pixel in image.(compose f g) Traditional Higher-Order Procedure.((compose f g) x) is the same as (f (g x)).(section procedure value-or-hole-1 ... value-or-hole-n) Mediascheme Higher-order Procedure/Macro.procedure, leaving the rest as parameters for the result procedure. Holes (parameters for the result proedure) are indicated with the <> symbol.(image-load filename) MediaScheme GIMP Procedure.(image-save image fname) MediaScheme GIMP Procedure.image in the specified file (which should provide the full path to the file). The type of the image (JPEG, GIF, PNG, etc.) is determined by the suffix of the file name.(image-show image) MediaScheme GIMP Procedure.(irgb-lighter irgb-color) MediaScheme Color Procedure.(irgb-darker irgb-color) MediaScheme Color Procedure.(irgb-redder irgb-color) MediaScheme Color Procedure(irgb-greener irgb-color) MediaScheme Color Procedure.(irgb-bluer irgb-color) MediaScheme Color Procedure.(irgb-rotate irgb-color) MediaScheme Color Procedure.(irgb-phaseshift irgb-color) MediaScheme Color Procedure.(irgb-complement irgb-color) MediaScheme Color Procedure.(irgb-add irgb-color-1 irgb-color-2) MediaScheme Color Procedure.irgb-color-1 and irgb-color-2. If any component sum is greater than 255, uses 255 for the resulting component.(irgb-average irgb-color-1 irgb-color-2) MediaScheme Color Procedure.irgb-color-1 and irgb-color-2.(irgb-subtract irgb-color-1 irgb-color-2) MediaScheme Color Procedure.irgb-color-2 from the corresponding components of irgb-color-1. If any component difference is less than 0, uses 0 for the resulting component.a. Start and connect GIMP and DrRacket using the steps from the previous labs.
b. If you did not already do the preparation from the self-check in the reading, please do it now.
a. Find an image you like, such as your campus directory picture (or President Kington’s directory picture), and save it to your desktop.
b. Using image-load, image-show, and anything else that you think will be useful, load and show that image. Note that the path to the file is likely to be something like "/home/username/Desktop/image.jpg", although you will need to replace the user name and image.
c. Name the loaded image pic.
d. Using image-load, image-show, and anything else you think will be useful, load and show "/home/curtsinger/public_html/images/profile.jpg". Name the loaded image prof.
e. Using image-variant, make prof a bit bluer.
f. Using image-save, save the modified image to your desktop.
g. Try opening the modified image by double-clicking on it.
h. You probably don’t need the modified image any more. Delete it.
As you may recall, the compose procedure composes multiple procedures , creating a new procedure that applies each in sequence to the result of the previous one.
Consider the following definition.
> (define irgb-modify2 (compose irgb-redder irgb-redder irgb-bluer irgb-bluer))
a. What RGB components do you expect to get if you apply irgb-modify2 to (irgb 127 127 127)?
b. Check your answer experimentally by entering the following expression.
> (irgb->string (irgb-modify2 (irgb 127 127 127)))
c. What effect do you expect to get if you apply irgb-modify2 to the image you obtained in exercise 1?
d. Check your answer experimentally.
Predict the effects of each of the following compound transformations, and then try them on a few sample colors and your image.
a. (compose irgb-rotate irgb-rotate irgb-rotate)
b. (compose irgb-lighter irgb-lighter irgb-lighter irgb-darker irgb-darker irgb-darker)
c. (compose irgb-rotate irgb-rotate irgb-bluer irgb-rotate)
d. An “interesting” compound transformation that you design yourself.
As you may recall from the reading, the section operation creates a new procedure from an existing procedure by filling in one or more parameters. In the reading, we considered section from the perspective of colors. For this lab, we’ll first explore it with numeric operations.
Consider the following definitions.
(define add10 (section + 10 <>))
(define add11 (section + <> 11))
(define sub5 (section - 5 <>))
(define sub6 (section - <> 6))
(define rem7a (section remainder <> 7))
(define rem7b (section remainder 7 <>))
a. What value do you expect to get if you apply each of these procedures to the value 12? What about the value 5?
b. Check your answer experimentally.
> (add10 12)
___
> (add11 12)
___
> (sub5 12)
___
> (sub6 12)
___
> (rem7a 12)
___
> (rem7b 12)
___
> (add10 5)
___
> (add11 5)
___
> (sub5 5)
___
> (sub6 5)
___
> (rem7a 5)
___
> (rem7b 5)
___
c. What do your results suggest about the behavior of section?
Consider the following definition.
(define proc (compose (section * 5 <>) (section - <> 2)))
a. What values do you expect to get when you apply proc to the inputs 1, 2, 3, 4, and 5?
b. Check your answer experimentally.
We’ve just used the section procedure to build arithmetic operations. But we can certainly use it to build color transformations from the binary color operations. Consider the following definitions.
(define irgb-modify-6a (section irgb-add (irgb 64 0 64) <>))
(define irgb-modify-6b (section irgb-average (irgb 64 0 64) <>))
(define irgb-modify-6c (section irgb-subtract (irgb 64 0 64) <>))
(define irgb-modify-6d (section irgb-subtract <> (irgb 64 0 64)))
a. What effect do you expect each of these procedures to have on the color (irgb 127 127 127)?
b. Check your answer experimentally.
c. What effect do you expect each of these procedures to have on your sample image?
d. Check your answer experimentally.
a. Suppose we did not have irgb-redder. How would you define it in terms of irgb-add, irgb-subtract, and/or irgb-average? (Yes, you can also use compose.)
b. Suppose we did not have irgb-complement. How would you define it in terms of irgb-add, irgb-subtract, and/or irgb-average? (Yes, you can also use compose.)
c. Suppose we did not have irgb-darker. How would you define it in terms of irgb-add, irgb-subtract, and/or irgb-average? (Yes, you can also use compose and o.)
Consider the following definitions.
(define k (image-load "/home/rebelsky/Desktop/kitten.jpg"))
(define proc8a (section image-variant <> irgb-complement))
(define proc8b (section image-variant k <>))
a. proc8a is a unary procedure. What type of parameter does proc8a expect? That is, does it expect a color, a string, an image, a color transformation, a number, or something else?
b. proc8b is a unary procedure. What type of parameter does proc8b expect? That is, does it expect a color, a string, an image, a color transformation, a number, or something else?
c. Give a sample call to proc8a.
d. Give a sample call to proc8b.
e. What does proc8a do? Come up with a better name for it.
f. What does proc8b do? Come up with a better name for it.
Explorations are intended for students interested in further exploring the design aspects of these techniques. They also provide students who finish early with extra activities that may challenge them in different ways. You may do them in any order.
While we only have a few basic transformations, there are, in some sense, an infinite number of ways to combine them. Try to find an interesting composition of basic transformations that someone might want to use as a filter.
As you have undoubtedly noticed, RGB colors are represented as integers. That means that we can transform colors with arithmetic operations as well as with component based operations. What do you think the following operations will do to your image? Try some of them to find out. Then, try a few of your own devising.
> (define t1 (section * 2 <>))
> (define t2 (section * 3 <>))
> (define t3 (section * 1.5 <>))
> (define t4 (section * 256 <>))
> (define t5 (section - <> (irgb 0 0 255)))
Make sure you save your work regularly. Some of these procedures have the potential to crash the GIMP or MediaScript.
Try developing your own interesting RGB transformation procedures and applying them to picture.