Transforming images
We explore techniques for transforming images, focusing on the use of anonymous procedures.
Procedures to remember
Basic color procedures
(rgb r g b)- create a new RGB color.(rgb r g b a)- create a new RGB color, also specifying the alpha channel.(rgb-red c)- extract the red component of an rgb color.(rgb-green c)- extract the green component of an rgb color.(rgb-blue c)- extract the blue component of an rgb color.
Transforming colors
(rgb-darker c)- create a darker version ofc(if possible).(rgb-ligheter c)- create a lighter version ofc(if possible).(rgb-redder c)- create a redder version ofc(if possible).(rgb-greener c)- create a greener version ofc(if possible).(rgb-bluer c)- create a bluer version ofc(if possible).(rgb-pseudo-complement c)- get the pseudo-complement ofc.(rgb-complement c)- get the HSV complement ofc.(rgb-greyscale c)- convert c to greysacle.(rgb-phaseshift c)- phase shift each component ofcby 128, adding 128 to values less than 128 and subtracting 128 from values greater than or equal to 128.(rgb-rotate-components c)- rotate the RGB components ofc.
Combining colors
(rgb-add c1 c2)- Add the components of two RGB colors.(rgb-subtract c1 c2)- Subtract corresponding components ofc2fromc1.(rgb-average c1 c2)- Average the components inc1andc2.
Working with color names
(all-color-names)- list all the color names.(color-name->rgb name)- convert a color name to an RGB color.(find-colors name)- find all the colors that include name.
Working with images
(with-image-file fn)- loads an image, callingfnwith the image as input.(with-image-from-url url fn)- loads an image fromurl, callingfnon the image as input.(pixel-map color-transformation image)- apply a color transformation to each pixel in an image.- `(image-save img filename) - save an image to a file.
Working with procedures
(section (expression-with-underscores))- Build a new procedure that takes one parameter for each underscore inexpression-with-underscores.(o fun1 fun2 fun3 ... funk)- Build a new procedure that appliesfunkthen ... thenfun3thenfun2thenfun1to its parameter.
The lab
- Use the file transforming-images.scm.
- Find an image you like, such as your campus directory picture (or President Harris' directory picture, or your instructor's directory picture) and save it to your desktop.
Acknowledgements
The kitten image was downloaded from http://public-photo.net/displayimage-2485.html. Unfortunately, the site behind that URL has disappeared. Nonetheless, the kitten image lives on.
This lab was originally written in 2024Sp, based on a lab from 2017Sp.