Download presentation
Presentation is loading. Please wait.
Published byBlaise Little Modified over 9 years ago
1
CS 102 Computers In Context (Multimedia) 01 / 28 / 2009 Instructor: Michael Eckmann
2
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Today’s Topics Questions/comments? JES/Jython programming –Defining a function –Call functions –Blocks –Syntax errors Digital images –Pixels –Grayscale / RGB Some JES functions that read and show an image Write a function that swaps the colors in an image
3
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Some Python def is used to define functions –A function is defined in the following way: def myFunName(parm1, parm2, parm3): statement1 statement2 statement3 statement4 Note: all statements in the body of the function must be indented like above and functions can have 0 or more parameters (the one above has 3).
4
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Some Python To call a function –give its name and in parentheses any required arguments (parameters) and if it returns something, we typically capture that value in a variable or do something with it. e.g. ord is a python function that takes one argument which is a character and returns the ASCII value of that character –Call it like so --- this will print the returned value: print ord('A') pickAFile is a JES function that takes no arguments and returns the name of the file that the user chooses –Call it like so print pickAFile() or fileName = pickAFile() Let's try pickAFile() now.
5
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Some Python Blocks –A block is a section of code that has the same indentation –For example, see the slide that I described def on. The four statements are in a block. –There can be subblocks within blocks Example on the board Syntax errors –Syntax errors occur if we try to run a program that has some text that the python interpreter cannot understand or if we type a command that the interpreter cannot understand. For example –Typing pint instead of print –Let's try some now
6
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Digital images A digital image is simply matrix (2 dimensional array) of numbers. Each element of the matrix is called a pixel and the numbers signify the color of that pixel. For grayscale images (sometimes misnamed as black-and-white images) each pixel is usually 1 byte (so it can have a value from 0- 255). For color images, each pixel is usually 3 bytes, one byte for each of the three channels (Red, Green and Blue.) Each of the color channels can have a value of 0-255. There are many other color formats but RGB is common and that's what we'll use in this course.
7
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Digital images The Red, Green and Blue colors can mix in 256*256*256 (over 16 million) ways. This does not cover the entire range of colors that humans can see, but seems to be more than “good enough” for most purposes. Let's look at how Red Green and Blue light mix to get a wide range of colors. Note that this is a different from the kind of mixing of color pigments. –Mixing pigments = subtractive color model like CMY –Mixing lights = additive color model like RGB
8
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Digital images Let's load up some images in Gimp (Gnu Image Manipulation Program) --- a program that has similar functionality to Adobe Photoshop --- and we'll view the pixel values. –For color images, RGB values: ( 0, 0, 0) = black ( 255, 255, 255) = white ( x, x, x) = some level of gray, where all the x's are the same value (200, 10, 4) = a red color etc.
9
Michael Eckmann - Skidmore College - CS 102 - Spring 2009 Some JES functions JES functions are those provided by the JES system and are not available in general in jython or python. pickAFile makePicture show Let's use these and then write a function that swaps the color channels of an image.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.