1 / 66

Digital Image M anipulation -2012 CS4HS @ UCA

Digital Image M anipulation -2012 CS4HS @ UCA. References: Introduction to computing and programming in Python – a multimedia approach by Mark Guzdial and Barbara Ericson JES: Jython Environment for Students , http://code.google.com/p/mediacomp-jes/

sakina
Download Presentation

Digital Image M anipulation -2012 CS4HS @ UCA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Digital Image Manipulation -2012 CS4HS @ UCA References: Introduction to computing and programming in Python – a multimedia approach by Mark Guzdial and Barbara Ericson JES: Jython Environment for Students, http://code.google.com/p/mediacomp-jes/ http://nifty.stanford.edu/2011/parlante-image-puzzle/ by Nick Parlante

  2. Outline of tasks 0. JES Introduction 1. Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  3. Outline of tasks 0. JES Introduction: 1.Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  4. JES: JythonEnvironment for Students • JES has a set of functions to manipulate media data (digital image and sounds) • Let us open the environment 2012 CS4HS @ UCA

  5. JES 4.3 2012 CS4HS @ UCA

  6. 2012 CS4HS @ UCA

  7. Outline of tasks 0. JES Introduction: 1. Load and investigate details of an image 2.Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  8. Pack a file to work with 2012 CS4HS @ UCA

  9. Let us pick the beach.jpg 2012 CS4HS @ UCA

  10. Let the computer remember it • Assign a name to the file we can then refer and use it later. myFile = pickAFile() 2012 CS4HS @ UCA

  11. View the picture • Let us make myFile an picture object myPict = makePicture(myFile) • Does print myPict work? print(myPict) • View myPict with show(myPict) 2012 CS4HS @ UCA

  12. Make a function: pick and show • We do not want to repeatedly type the same commands to load and show a picture every time • Let us create it once and be able to use it whenever needed 2012 CS4HS @ UCA

  13. pickAndShow() 2012 CS4HS @ UCA

  14. Let us save it • File -> Save Program • Specify the location (your USB drive), and give it a name (say prog1) • Exit JES • Open JES again • File -> Open Program • Select prog1 • It comes back 2012 CS4HS @ UCA

  15. Load program and use it • Click “Load Program” • Then, in the command line area type pict1 = pickAndShow() pict2 = pickAndShow() 2012 CS4HS @ UCA

  16. 2012 CS4HS @ UCA

  17. Investigate the details • Now let us investigate the details of a digital picture • Pick “MediaTools” from the menu bar, then select “Picture Tool …” 2012 CS4HS @ UCA

  18. (0, 0) (639, 0) x y (639, 479) (0, 479) 2012 CS4HS @ UCA

  19. Outline of tasks 0. JES Introduction: 1. Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  20. Get a pixel and find its color value 2012 CS4HS @ UCA

  21. Change color value of a pixel 2012 CS4HS @ UCA

  22. Image manipulation • It is all about changing color values of pixels • The process should be: • get a specific pixel first, and • then reset its color. • Do we want to type all the command lines above for every pixel again and again? • The picture has 640 x 480 = 307,200 pixels. • How should we do it? • For example, how do we zero out red values for all pixels? 2012 CS4HS @ UCA

  23. JES Functions • JES Functions -> Pictures -> getPixels • By using the function getPixels, we can get all pixels at once. • We then loop through each pixel to zero out its red value. • Let us open our prog1 and create another function named ZeroRed 2012 CS4HS @ UCA

  24. 2012 CS4HS @ UCA

  25. Now let us use it • Load Program • Pick a picture • Zero red out for all pixels in the picture • View the changes with Picture Tool … 2012 CS4HS @ UCA

  26. Work with the pictureModule • We provide you a collection of functions in the pictureModule.py • Open and load the module • Here are some available functions: • pickAndShow() • changeRed( pict, alpha ) • changeGreen( pict, alpha ) • changeBlue( pict, alpha ) • …… 2012 CS4HS @ UCA

  27. chageRed(pict, alpha) defchangeRed( pict, alpha ): allPixels = getPixels( pict ) for p in allPixels: value = alpha * getRed( p ) if value > 255: value = 255 setRed( p, value) 2012 CS4HS @ UCA

  28. Change values of Green and Blue • changeGreen( pict, alpha) • changeBlue ( pict, alpha) 2012 CS4HS @ UCA

  29. Outline of tasks 0. JES Introduction: 1. Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  30. Solve a puzzle • Load the image copper-puzzel.png pic = pickAndShow() • A picture is hidden in. • Let’s find it? 2012 CS4HS @ UCA

  31. Solution • Zero out redness • Increase greenness 20 times for all pixels • Increase the blueness 20 times for all pixels 2012 CS4HS @ UCA

  32. Solve two more puzzles • iron-puzzle.png, and Hint: Increase redness 15 times for all pixels • canvas.png Hint: Increase blueness 16 times 2012 CS4HS @ UCA

  33. How do we create a puzzle? • Zero out R, G, or B • Weak the remaining color • Add randomly generated values for the zero out color 2012 CS4HS @ UCA

  34. Outline of tasks 0. JES Introduction: 1. Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  35. Hiding a message in a picture (steganography) A scenic picture (original) This picture with a hidden message 2012 CS4HS @ UCA

  36. 2012 CS4HS @ UCA

  37. Problem specification • Inputs: • A cover image • A message • Outputs: • An image seems exactly as the original but with the message embedded • From the image, one can recover the embedded message 2012 CS4HS @ UCA

  38. Solution design • To embed the message, we need to identify the position of each pixel of the message and remember them. • To remember the position of a pixel, we only need to change the original very little such that the altered image seem exactly as the original • When we need to reveal the message, we only need to print the pixels at the positions remembered. 2012 CS4HS @ UCA

  39. Solution design continue • To identify the position of each pixel of the message, we check if a pixel is close to black (or whatever color the text is). • To remember the position of a pixel, we do the followings: • Preparation: Make the red (or green, blue) value of each pixel even. • Memorization: For each message pixel, add one to the red value (become odd now). • Note: These two steps change the original very little • To reveal the message, we only need to print the pixels whose red value is odd. 2012 CS4HS @ UCA

  40. Implementation: encode def stegano(msgPic, coverPic): for pxl in getPixels(coverPic): r = getRed(pxl) if r%2 ==1: setRed(pxl, r-1) for x in range(1, getWidth(coverPic)): for y in range(1, getHeight(coverPic)): msgPxl = getPixel(msgPic, x, y) coverPxl = getPixel(coverPic, x, y) if distance(getColor(msgPxl), black) < 100.0: setRed(coverPxl, getRed(coverPxl) +1) return coverPic 2012 CS4HS @ UCA

  41. Implementation: decode def deStega(segaPic): w = getWidth(segaPic) h = getHeight(segaPic) msg = makeEmptyPicture(w, h) for x in range(0,w): for y in range(0, h): encPxl = getPixel(segaPic, x, y) msgPxl = getPixel(msg, x, y) if (getRed(encPxl)%2) ==1: setColor(msgPxl, black) show(msg) return msg 2012 CS4HS @ UCA

  42. Integration and maintenance • The application should be either to encode a message in a cover image or discover the message from an encoded image. • For the former, we need to pick a cover image, then a message as an image. Then, encode it. • For the later, we need to recover the message from its cover image. 2012 CS4HS @ UCA

  43. Let us do it • Open and load the pictureModule • Load two pictures, one is the cover image and the other is the text image, with coverPic = pickAndShow() msg = pickAndShow() • Embed the message in the cover image secret = stegano (coverPic, msg) • Save it with JES Functions -> Pictures -> writePictureTo • Note: use the .png extension not .jpg 2012 CS4HS @ UCA

  44. Recover the message • Load the picture that you just saved pic = pickAndShow() • The, decipher it with deStega(pic) 2012 CS4HS @ UCA

  45. Outline of tasks 0. JES Introduction: 1. Load and investigate details of an image 2. Alternate pixel RGB values 3. Solve image puzzles 4. Embed information in a picture 5. Fix the Temple of Hephaestus virtually 6. Land Mark on the moon 2012 CS4HS @ UCA

  46. Let us fix the temple in Athens • What is the problem specification? • How do we design a solution? • Implement it • Test and refine the computational solution 2012 CS4HS @ UCA

  47. How do we fix it? • Due the symmetry, we may flip the left half to the right • How do we do it? 2012 CS4HS @ UCA

  48. Try to fix it with reflection 2012 CS4HS @ UCA

  49. Mirroring a picture -vertically 2012 CS4HS @ UCA

  50. Specification • The center line is x = midpoint = width/2. • The x-coordinate of a pixel on the left half is: width/2 - offset • The x-coordinate of a pixel on the right half is: width/2 + offset 2012 CS4HS @ UCA

More Related