We’ll be using jes (Jython Environment for Students). We’ll be using jes



Yüklə 1,07 Mb.
tarix07.11.2018
ölçüsü1,07 Mb.
#78904



We’ll be using JES (Jython Environment for Students).

  • We’ll be using JES (Jython Environment for Students).

  • Install the version JES 4.3 (Jython environment for students) available as free download: http://code.google.com/p/mediacomp-jes/





Anything you type in command area is evaluated and its value is displayed

  • Anything you type in command area is evaluated and its value is displayed

  • Example:



Up/down arrows walk through command history

  • Up/down arrows walk through command history

  • You can edit the line at the bottom

    • Just put the cursor at the end of the line before hitting Return/Enter.


JES defines some special functions for media computation

  • JES defines some special functions for media computation















makeEmptyPicture(width,height) creates a new empty picture

  • makeEmptyPicture(width,height) creates a new empty picture

  • show(picture) displays a picture in a separate window

    • >>> pic1 = makeEmptyPicture(200,100)
    • >>> show(pic1)
    • >>> setAllPixelsToAColor(pic1, red)
    • >>> show(pic1)
    • >>> addText(pic1,30,50,“hello")
  • similarly can add rectangles, lines, etc.















The JES Functions menu has functions arranged by type - check them out!

  • The JES Functions menu has functions arranged by type - check them out!

  • Can you find a function that saves a file?

  • Can you find under what category pickAFile() is listed?



Create a function that…

  • Create a function that…

    • Causes an interactive input window to pop up and request some form of input from the user and stores it in a variable
    • Displays the value stored in the variable
    • Displays an image
  • Save your function in a file

  • Load it

  • Use the function in the command area to make sure that it works and does what you want it to do



makePicture(filename) creates and returns a picture object, from the .JPG or .PNG file at the filename

  • makePicture(filename) creates and returns a picture object, from the .JPG or .PNG file at the filename

  • We’ll learn functions for manipulating pictures later, like getColor(), setColor(), and repaint()



Some names for common colors are predefined – try using the names: yellow, black, white, etc.

  • Some names for common colors are predefined – try using the names: yellow, black, white, etc.

  • makeColor() takes red, green, and blue values (in that order) between 0 and 255, and returns a Color object

  • pickAColor() lets you use a color chooser and returns the chosen color





Colors go from

  • Colors go from

  • (0,0,0) to (255,255,255)





setMediaPath(): Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\"

  • setMediaPath(): Prompts the user to pick a folder on the computer. JES then will look for files in that directory unless given a full path, i.e. one that starts with "c:\"

  • writePictureTo(picture, path): picture: the picture you want to be written out to a file path: the path to the file you want the picture written to Takes a picture and a file name (string) as input, then writes the picture to the file as a JPEG.

  • Example:

  • >>> setMediaPath()

  • writePictureTo(pic, “mypic.jpg”)



if age < 18:

  • if age < 18:

  • showInformation(“Sorry, not allowed to vote yet.”)

  • else:

  • showInformation(“Please select candidate.”)



for number in range(0,N):

  • for number in range(0,N):

  • pic = ....

  • filename = base + str(number)

  • writePictureTo(pic, filename)



[“hi”, “hello”, “howdy”, “hiya”, “yo”]

  • [“hi”, “hello”, “howdy”, “hiya”, “yo”]

  • [10, 23, 15]

  • []

  • range(0,6)

  • range(1,4)

  • range(3,8)



Create a function makeMeSwatches() that makes lots of color swatches (small solid-colored image files). Specifically, your function should:

  • Create a function makeMeSwatches() that makes lots of color swatches (small solid-colored image files). Specifically, your function should:

  • display a welcome message to the user

  • ask the user to say how many swatches

  • ask the user to select a folder for storing the swatches

  • create small files with images of solid color save each one in the selected folder with names "swatch0.jpg", "swatch1.jpg", "swatch2.jpg", etc

  • display a message letting the user know that it is finished.





>>> p = getPixel(picture,12,9)

  • >>> p = getPixel(picture,12,9)

  • >>> print p

  • Pixel, red=108 green=86 blue=142



getRed(p),

  • getRed(p),

  • getGreen(p)

  • getBlue(p)

  • setRed(p, value)

  • setGreen(p, value)

  • setBlue(p, value)



getColor(p) takes a pixel as input and returns a Color object with the color at that pixel

  • getColor(p) takes a pixel as input and returns a Color object with the color at that pixel

  • setColor(p, c) sets the color of pixel (p) as input and a color (c), then sets the pixel to that color.

  • We also have functions that can makeLighter(c) and makeDarker(c) an input color

  • Last time we saw that we can also create colors:

    • makeColor(r,g,b) takes red, green, and blue values (in that order) between 0 and 255, and returns a Color object
    • pickAColor() lets you use a color chooser and returns the chosen color


>>> pixel=getPixel(picture,12,9)

  • >>> pixel=getPixel(picture,12,9)

  • >>> print pixel

  • Pixel, red=108 green=86 blue=142

  • >>> value = getRed(pixel)

  • >>> setRed (pixel, value+50)

  • >>> setGreen(pixel, 0)

  • >>> setBlue(pixel, getBlue(pixel)/2)



>>> pixel=getPixel(picture,12,9)

  • >>> pixel=getPixel(picture,12,9)

  • >>> print pixel

  • Pixel, red=108 green=86 blue=142

  • >>> value = getRed(pixel)

  • >>> setRed (pixel, value+50)

  • >>> setGreen(pixel, 0)

  • >>> setBlue(pixel, getBlue(pixel)/2)



>>> pixel=getPixel(picture,12,9)

  • >>> pixel=getPixel(picture,12,9)

  • >>> print pixel

  • Pixel, red=108 green=86 blue=142

  • >>> redValue = getRed(pixel)

  • >>> greenValue = getGreen(pixel)

  • >>> blueValue = getBlue(pixel)

  • >>> newColor = makeColor(redValue+50, 0, getBlue(pixel)/2)

  • >>> setColor(pixel, newColor)



>>> pixel=getPixel(picture,12,9)

  • >>> pixel=getPixel(picture,12,9)

  • >>> print pixel

  • Pixel, red=108 green=86 blue=142

  • >>> redValue = getRed(pixel)

  • >>> greenValue = getGreen(pixel)

  • >>> blueValue = getBlue(pixel)

  • >>> newColor = makeColor(redValue+50, 0, getBlue(pixel)/2)

  • >>> setColor(pixel, newColor)



  • Example:

  • for p in getPixels(picture):     value = getRed(p)     setRed(p, value*0.5)



  • Example:

  • def decreaseRed(picture):

  • for p in getPixels(picture):     value = getRed(p)     setRed(p, value*0.5)



More examples (link)   - you can copy and paste these to save time

  • More examples (link)   - you can copy and paste these to save time

  • decreaseGreen()

  • decreaseBlue()

  • clearBlue()

  • lighten()

  • darken()

  • negative()

  • grayScale()



Create a menu-driven picture manipulation function that allows the user to make various changes to images. Here is the algorithm:

  • Create a menu-driven picture manipulation function that allows the user to make various changes to images. Here is the algorithm:

  • welcome the user to your program

  • get the user to select a picture to work on

  • show(picture)

  • ask the user select one of the following options:

    • Make picture grayscale
    • Decrease red by 10%
    • Decrease green by 10%
    • Decrease blue by 10%
    • “Posterize” (see below)
  • repaint(picture)

  • ask user whether to save the new picture, and if the response is “y”, save it

  • show goodbye/thank you message

  • Links to small images you can use to test your program: eye.jpg, luca.jpg





Example:

  • Example:

  • requestIntegerInRange(“Please enter one of the following

  • requestIntegerInRange(“Please enter one of the following options: 1) grayscale, 2) reduce red,

  • requestIntegerInRange(“Please enter one of the following options: 1) grayscale, 2) reduce red, 3) reduce green, 4) reduce blue, 5) posterize”)



Special characters that cannot be used directly as part of a string, eg:

  • Special characters that cannot be used directly as part of a string, eg:

  • \n – new line

  • \t – tab

  • \\ – backslash (\)

  • \’ – single quote

  • Example:

  • showInformation(“see you\nlater”)



The knowledge that a secret exists is half of the secret --  Joshua Meyrowitz

  • The knowledge that a secret exists is half of the secret --  Joshua Meyrowitz

  • From the Greek words στεγανός and γράφω meaning “covered writing.” 

  • Art and Science of hiding information in ways that prevent detection.

  • Can be used on audio, text, packet headers, or images 

  • Similar to Cryptography –Cryptography: scrambles message –Steganography: hides message



Least Significant Bit (LSB)

  • Least Significant Bit (LSB)

  • One of most common techniques

  • Alters LSB of each pixel (1 bit out of 24 --or 1 out of 8 for grayscale)

  • Uses the concept of parity, ie, even numbers in binary end in 0, odd ones end in 1

  • Easiest to implement: hiding bitmaps in a color picture

  • Hiding ASCII code, one letter at a time



To hide letter C (1000011) in a grayscale file: 

  • To hide letter C (1000011) in a grayscale file: 

  • Original: 

  • 01001101 01001110 01001110 01001111 01010000 01010000 01001111

  •  

  • 1 0 0 0 0 1 1

  • Encoded: 

  • 01001101 01001110 01001110 01001110 01010000 01010001 01001111



def encode(picture, message):   import java.awt.Font as Font   myFont = makeStyle("Arial", Font.BOLD, 24)   msgPicture = makeEmptyPicture(getWidth(picture), getHeight(picture), white)   addTextWithStyle(msgPicture,10,28,message, myFont, black)   encodePicture(picture, msgPicture)

  • def encode(picture, message):   import java.awt.Font as Font   myFont = makeStyle("Arial", Font.BOLD, 24)   msgPicture = makeEmptyPicture(getWidth(picture), getHeight(picture), white)   addTextWithStyle(msgPicture,10,28,message, myFont, black)   encodePicture(picture, msgPicture)

  • def encodePicture(picture, msgPicture):   for pxl in getPixels(picture):     if (getRed(pxl) % 2) == 1:       setRed(pxl, getRed(pxl) - 1)   for x in range(0, getWidth(picture)):     for y in range(0, getHeight(picture)):       msgPxl = getPixel(msgPicture, x, y)       origPxl = getPixel(picture, x, y)       if distance(getColor(msgPxl), black) < 100.0:         setRed(origPxl, getRed(origPxl)+1)



Need to determine which pixels have been changed.

  • Need to determine which pixels have been changed.

  • No need to have original image – the rightmost bit of the image with the code does not depend on the original

  • We can thus loop through the pixels and reconstruct the message image



Menu-driven picture manipulation set of functions. Algorithm:

  • Menu-driven picture manipulation set of functions. Algorithm:



Yüklə 1,07 Mb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə