Tuesday, November 29, 2016

CST 205 Week 5

CST 205 Week 5

I read a chapter about tips on debugging. I found it very useful. I especially liked the idea of printing variables to see what the are doing at the beginning of loops and recursive functions. It gave good tips on creating many functions to minimize debugging time on large groups of code. Reading this chapter helped put a perspective that readability and simplicity of code is essential in order to make debugging easier. Finally the tip of taking a break is good as frustration only gets worse when in front of the computer.

Top down programming is creating a program by first starting with the overall scope of the project and moving to smaller pieces of the project. Bottom up programming is just the opposite where you move from the smallest tasks first that a part of the whole to end up with compiling them together for the finished product at the end. Either choice can be effective if different scenarios; the key is to always have a plan in place.

Here are some good sources for debugging that I found:

https://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/


https://zapier.com/engineering/debugging-python-boss

https://www.youtube.com/watch?v=g49UECaIDOs

This week we worked as a group to make a text based game. This assignment was right up my ally as I am wanting to enter a career in game development. Although the assignment was simplistic it gave  a good understanding of the collaboration necessary in creating a quality game. We could easily have expanded upon this game and taken months to achieve the desired product. We used a top down approach in the game design. First designing the overall rooms and layout of the house and then dividing up the sections among team members to complete. We then met to collaborate and mold all of the pieces together. This assignment was fun, challenging, and educational.

Wednesday, November 23, 2016

CST 205 Week 4

CST 205 Week 4

It was fun to finish my midterm project. I chose to make a Matrix filter to show what a picture may look like if view from the Matrix movie. This was a fun project.

It was interesting learning about sound as I have never known in depth how sound was converted digitally. The section on string manipulation was a good refresher and necessary for our hangman project. I am not sure why volume is lost when manipulating sound in Jython. I found this week to be challenging as there was a lot to do coupled with creating a video for lab #10. The sound labs were fun as I got to search for sounds that interested me. The hangman lab was a bit challenging. I was able to utilize for and while loops to achieve the desired affect for the game. This problem challenged my problem solving abilities and I look forward to future problems like this.

Wednesday, November 16, 2016

CST 205 Week 3

CST 205 Week 3

This week I learned about how to use Github to upload documents and share with teamates. I had heard of Github before but never used it. This will be an effective tool in colaboration among team mates for group projects.
The project to create a Thanksgiving card was a fun way to showcase everything I have  learned so far in the course. I was able to utilize make Negative(), pyCopy(), chomakey(), and a custom makeOrange() filter. A challenge was figuring out how to get text to skip to a next line inside the addText() JES function. It was discovered that \n does not work for this. I had to improvise and create a for loop to get the text the way I wanted it. 
I was also able to showcase all the functions I have created so far with a portfolio project. I am glad I have this for a reference to what I have done.
Finally our team met and decided who would be paired with who to work on our mid term projects. Joel and I are paired together and began working on the CSUMBY function as well as a custom Matrix function. I look forward to finishing this project next week.

Tuesday, November 15, 2016

Image Portfolio

Image Portfolio

Rose Colored Glasses


















This function takes an image and adds a rosy hue to it. To achive this effect, I manipulated the green and blue values of each pixel. Each green value became 40% of the red value for that pixel and each blue value became 80% of the red value for that pixel. Here is the corresponding code:

def roseColoredGlasses(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    setGreen(p, r * .4)
    setBlue(p, r * .8)
  repaint (pic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//Rose.jpg")

Negative


























This functiong takes an image and creates a negative image of it. To achieve, this effect I took the RGB values for each pixel and subtracted each value from 255 to get the negative RGB value. During this exercise, I learned that each RGB value ranges between 0 and 255. Here is the corresponding code:

def makeNegative(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    r = 255 - r
    setRed(p, r)
    g = getGreen(p)
    g = 255 - g
    setGreen(p, g)
    b = getBlue(p)
    b = 255 - b
    setBlue(p, b)
  repaint (pic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//Negative.jpg")

Better Black and White


























This function takes a color image and converts it to a black and white image. To achieve this effect, I took the RGB values for each pixel and then weighted them so that R = 29.9%, G = 58.7%, and B = 11.4%. I then added these values up and divided by 3 to get a luminace value for the pixel. The luminace value is then used to set the RGB value for the pixel because all RGB values for a pixel must be equal to achieve a gray scale. Here is the corresponding code:

def betterBnW(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    g = getGreen(p)
    b = getBlue(p)
    luminace = ((r * .299) + (g * .587) + (b * .114))
    setRed(p, luminace)
    setGreen(p, luminace)
    setBlue(p, luminace)
  repaint (pic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//BlackandWhite.jpg")

Bottom to Top Mirror





























This function takes an image and mirrors it horizontally by taking the bottom portion of the image and applying it upside down to the top portion of the image. The loop on the y axis starts at the center of the image and works it's way down to the bottom of the page. The loop on the on the x axis works left to right across the x axis. It then takes the pixel and copies it tothe pixel the middle of the page working its way up. Here is corresponding code:

def horizontalMirrorBottomTop(picture):
  pic = picture
  y2 = getHeight(pic)/2
  for y in range(getHeight(pic)/2, getHeight(pic)):
    y2 = y2 - 1
    for x in range(0, getWidth(pic)):
      p = getPixel(pic, x, y)
      p2 = getPixel(pic, x, y2)
      col = getColor(p)
      setColor(p2, col)
  repaint(pic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//horizontalMirrorBottomTop.jpg")

Shrink





















This function takes an image and creates a copy of the image that is half the size. This is done by omitting every other pixel in the image and applying it to the new canvas that is half the size of the original. Here is the corresponding code:

def shrink(picture):
  pic = picture
  mypic = makeEmptyPicture((getWidth(pic)/2) + 1, (getHeight(pic)/2) + 1)
  x2 = -1
  for x in range(0, getWidth(pic), 2):
    x2 = x2 + 1
    y2 = 0
    for y in range(0, getHeight(pic), 2):
      p = getPixel(pic, x, y)
      p2 = getPixel(mypic, x2, y2)
      col = getColor(p)
      setColor(p2, col)
      y2 = y2 + 1
  show(mypic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//shrinkBurger.jpg")
  return mypic

Collage

























This function utilized all I had learned about image manipulation in Python so far to create a collage of images. Several functions were used to create this collage. They include: makeCollage() function, Copy() function, pyCopy(), makeBlankPic(), verticalMirror(), horizontalMirror(), qaudrupleMirror(), rotatePic(), shrink(), roseColoredGlasses(), makeNegative(), artify(), and chromakey() functions. This project was not difficult just time consuming as much time was spent in the planning phase of getting the images put in the right spot on the new canvas. Here is the corresponding code:

# This function creates a collage of manipulated images on a 9.5 X 11 inch canvas
def makeCollage():
  background = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//grey_background.gif")
  vmirror = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Star Wars Background.jpg")
  vmirror = verticalMirror(vmirror)
  hmirror = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Tortuga Hall.jpg")
  hmirror = horizontalMirror(hmirror)
  rotatemirror = rotatePic(hmirror)
  qmirror = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Y.jpg")
  qmirror = quadrupleMirror(qmirror)
  grouppic = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Group Photo 2.png")
  shrunk = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//O.jpg")
  shrunk = shrink(shrunk)
  tpic = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//T.jpg")
  tpic = roseColoredGlasses(tpic)
  negative = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Earth.jpg")
  negative = makeNegative(negative)
  otter = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//otter.jpg")
  otter = artify(otter)
  falcon = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Falcon.jpg")
  mountain = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//Mountain.jpg")
  greenscreen = chromakey(falcon, mountain)
  blank = makeBlankPic()
  pic1 = pyCopy(background, blank, 0, 0)
  pic1 = pyCopy(vmirror, pic1, 33, 33)
  pic1 = pyCopy(rotatemirror, pic1, 2000, 33)
  pic1 = pyCopy(grouppic, pic1, 1600, 1000)
  pic1 = pyCopy(qmirror, pic1, 1250, 125)
  pic1 = pyCopy(shrunk, pic1, 143, 2033)
  pic1 = pyCopy(tpic, pic1, 33, 800)
  pic1 = pyCopy(negative, pic1, 1250, 1750)
  pic1 = pyCopy(greenscreen, pic1, 550, 2500)
  pic1 = pyCopy(otter, pic1, 1700, 2400)
  writePictureTo(pic1, "D://Downloads//School//CST 205//Week 1 Pictures//Collage.jpg")
  explore(pic1) 

# This function creates a simple copy of an image in  a larger background
def Copy():
  pic = get_pic()
  mypic = makeEmptyPicture(getWidth(pic)*2, getHeight(pic)*2)
  x2 = (getWidth(mypic)/4) - 1
  for x in range(0, getWidth(pic) - 1):
    y2 = getHeight(mypic)/4
    x2 = x2 + 1
    for y in range(0, getHeight(pic) - 1):
      p = getPixel(pic, x, y)
      p2 = getPixel(mypic, x2, y2)
      col = getColor(p)
      setColor(p2, col)
      y2 = y2 + 1
  show(mypic)
  return mypic
  
# This function creates a simple copy of an image in a larger background with given parameters
def pyCopy(source, target, targetX, targetY):
  oldpic = duplicatePicture(source)
  newpic = duplicatePicture(target)
  x2 = targetX
  for x in range(0, getWidth(oldpic) - 1):
    y2 = targetY
    x2 = x2 + 1
    for y in range(0, getHeight(oldpic) - 1):
      p = getPixel(oldpic, x, y)
      pixeltarget = getPixelAt(newpic, x2, y2)
      newcolor = getColor(p)
      setColor(pixeltarget, newcolor)
      y2 = y2 + 1
  return newpic
  
# This function makes a blank image of a sheet 8.5 x 11 inches
def makeBlankPic():
  return makeEmptyPicture(2550, 3300)
  
# This function creates a mirror image of a picture vertically down the middle
def verticalMirror(picture):
  pic = picture
  x2 = getWidth(pic)
  for x in range(0, getWidth(pic)/2):
    x2 = x2 - 1 
    for y in range(0, getHeight(pic)):
      p = getPixel(pic, x, y)
      p2 = getPixel(pic, x2, y) 
      col =  getColor(p)
      setColor(p2, col)
  return(pic)
  
# This function creates a mirror image of a picture horizontally across the middle
def horizontalMirror(picture):
  pic = picture
  y2 = getHeight(pic)
  for y in range(0, getHeight(pic)/2):
    y2 = y2 - 1
    for x in range(0, getWidth(pic)):
      p = getPixel(pic, x, y)
      p2 = getPixel(pic, x, y2)
      col = getColor(p)
      setColor(p2, col)
  return pic
  
# This function creates a quadruple mirror of an impage
def quadrupleMirror(picture):
  pic = picture
  x2 = getWidth(pic)
  for x in range(0, getWidth(pic)/2):
    x2 = x2 - 1 
    for y in range(0, getHeight(pic)):
      p = getPixel(pic, x, y)
      p2 = getPixel(pic, x2, y) 
      col =  getColor(p)
      setColor(p2, col)
  y2 = getHeight(pic)
  for y in range(0, getHeight(pic)/2):
    y2 = y2 - 1
    for x in range(0, getWidth(pic)):
      p = getPixel(pic, x, y)
      p2 = getPixel(pic, x, y2)
      col = getColor(p)
      setColor(p2, col)
  return pic
 
  
# This function rotates a picture 90 degrees and creates a copy of it
def rotatePic(picture):
  pic = picture
  mypic = makeEmptyPicture(getHeight(pic), getWidth(pic))
  for x in range(0, getWidth(pic)):
    x2 = getWidth(mypic)
    for y in range(0, getHeight(pic)):
      x2 = x2 - 1
      p = getPixel(pic, x, y)
      p2 = getPixel(mypic, x2, x)
      col = getColor(p)
      setColor(p2, col)
  return mypic
  
  
# This function creates a copy of a picture that is half the size
def shrink(picture):
  pic = picture
  mypic = makeEmptyPicture((getWidth(pic)/2) + 1, (getHeight(pic)/2) + 1)
  x2 = -1
  for x in range(0, getWidth(pic), 2):
    x2 = x2 + 1
    y2 = 0
    for y in range(0, getHeight(pic), 2):
      p = getPixel(pic, x, y)
      p2 = getPixel(mypic, x2, y2)
      col = getColor(p)
      setColor(p2, col)
      y2 = y2 + 1
  return mypic

# This function makes the picture have a pink hue
def roseColoredGlasses(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    setGreen(p, r * .4)
    setBlue(p, r * .8)
  return pic
   
# This function makes a negative image of the picture
def makeNegative(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    r = 255 - r
    setRed(p, r)
    g = getGreen(p)
    g = 255 - g
    setGreen(p, g)
    b = getBlue(p)
    b = 255 - b
    setBlue(p, b)
  return pic
      
# This function creates a customized posterization of an image
def artify(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    g = getGreen(p)
    b = getBlue(p)
    if r < 33:
      setRed(p, 33)
    elif 32 < r < 99:
      setRed(p, 66)
    elif 98 < r < 133:
      setRed(p, 99)
    elif 132 < r < 177:
      setRed(p, 133)
    elif 176 < r < 199:
      setRed(p, 177)
    elif 198 < r < 233:
      setRed(p, 199)
    elif 232 < r < 256:
      setRed(p, 233)
    if g < 33:
      setGreen(p, 33)
    elif 32 < g < 99:
      setGreen(p, 66)
    elif 98 < g < 133:
      setGreen(p, 99)
    elif 132 < g < 177:
      setGreen(p, 133)
    elif 176 < g < 199:
      setGreen(p, 177)
    elif 198 < g < 233:
      setGreen(p, 199)
    elif 232 < g < 256:
      setGreen(p, 233)
    if b < 33:
      setBlue(p, 33)
    elif 32 < b < 99:
      setBlue(p, 66)
    elif 98 < b < 133:
      setBlue(p, 99)
    elif 132 < b < 177:
      setBlue(p, 133)
    elif 176 < b < 199:
      setBlue(p, 177)
    elif 198 < b < 233:
      setBlue(p, 199)
    elif 232 < b < 256:
      setBlue(p, 233)
  return pic
  
def chromakey(picture1, picture2):
  pica = picture1   # Green Screen
  picb = picture2   # Background
  pixels = getPixels(pica)
  pixelsB = getPixels(picb)
  for p in pixels:
     r = getRed(p)
     g = getGreen(p)
     b = getBlue(p)
     if (r + b) <= g:
       xA = getX(p)
       yA = getY(p)
       pixB = getPixel(picb, xA, yA)
       newColor = getColor(pixB)
       setColor(p, newColor)
  return pica

Red Eye Reduction























f





















This function takes an image and reduces the red eye in the image. Being one of the first functions to create, it was a bit challenging as it was not understood yet about reducing the red in a given section of an image. Instead applied the red eye reduction to the entire image which is why there is black pixelation in the bottom right portion of the image. Here is the corresponding code:

def redEye(picture):
  picture = picture
  redRem = makeColor(235,115,132)
  orang = makeColor(521,227,107)
  orang1 = makeColor(184, 131, 45)
  yelo = makeColor(253,249,211)
  aqua = makeColor(51,204,255)
  red1 = makeColor(155, 42, 45)
  red2 = makeColor(198, 79, 86)
  for x in range(0,getWidth(picture)):
    for y in range(0,getHeight(picture)):
      px = getPixel(picture,x,y)
      color = getColor(px)
      if distance(color, redRem) < 50.0:
        setColor(px,black) 
      if distance(color,yelo) < 50.0:
        setColor(px,black) 
      if distance(color, orang) < 80.0:
        setColor(px,black)
      if distance(color, orang1) < 50.0:
        setColor(px, black)
      if distance(color, red1) < 50.0:
        setColor(px, black)
      if distance(color, red2) < 50.0:
        setColor(px, black)
  show(picture)
  writePictureTo(picture, "D://Downloads//School//CST 205//Week 1 Pictures//redEyeRabbit.jpg")
  return(picture)

Color Artify

































This function creates a customized posterization of an image. It utilizeds if  and elif statements to determine a RGB value range and if it falls within a certan range sets the value accordingly. Here is the corresponding code:

def artify(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    g = getGreen(p)
    b = getBlue(p)
    if r < 33:
      setRed(p, 33)
    elif 32 < r < 99:
      setRed(p, 66)
    elif 98 < r < 133:
      setRed(p, 99)
    elif 132 < r < 177:
      setRed(p, 133)
    elif 176 < r < 199:
      setRed(p, 177)
    elif 198 < r < 233:
      setRed(p, 199)
    elif 232 < r < 256:
      setRed(p, 233)
    if g < 33:
      setGreen(p, 33)
    elif 32 < g < 99:
      setGreen(p, 66)
    elif 98 < g < 133:
      setGreen(p, 99)
    elif 132 < g < 177:
      setGreen(p, 133)
    elif 176 < g < 199:
      setGreen(p, 177)
    elif 198 < g < 233:
      setGreen(p, 199)
    elif 232 < g < 256:
      setGreen(p, 233)
    if b < 33:
      setBlue(p, 33)
    elif 32 < b < 99:
      setBlue(p, 66)
    elif 98 < b < 133:
      setBlue(p, 99)
    elif 132 < b < 177:
      setBlue(p, 133)
    elif 176 < b < 199:
      setBlue(p, 177)
    elif 198 < b < 233:
      setBlue(p, 199)
    elif 232 < b < 256:
      setBlue(p, 233)
  repaint(pic)
  writePictureTo(pic, "D://Downloads//School//CST 205//Week 1 Pictures//Artify.jpg")

Green Screen











































This function takes a green screen image and another image and replaces the green screen portion with the second image. To achieve this an if statement is used to determine if the red plus blue value of a pixel are less than or equal to the green value of the pixel. If it is it replaces that pixel which should be the green screen portion with the pixel from the other image. Here is the corresponding code:

def chromakey(picture1, picture2):
  pica = picture1   # Green Screen
  picb = picture2   # Background
  pixels = getPixels(pica)
  pixelsB = getPixels(picb)
  for p in pixels:
     r = getRed(p)
     g = getGreen(p)
     b = getBlue(p)
     if (r + b) <= g:
       xA = getX(p)
       yA = getY(p)
       pixB = getPixel(picb, xA, yA)
       newColor = getColor(pixB)
       setColor(p, newColor)
  show(pica)
  writePictureTo(pica, "D://Downloads//School//CST 205//Week 1 Pictures//Chromakeyexample.jpg")

Thanksgiving Card




















































This project utilized several functions to merge an image onto a green screen image and copy the turkey image on top. The turkey image had to go through the makeNegative() function so the black background merged with the main canvas black background. It then used a function to create an orange hue to align with Fall colors. Text was added in a for loop to get it to appear on seperately lines. This was a challence as it was discovered that the addText() function in JES does not accurately utilize \n to go to a next line in a string passed to it. Here is the corresponding code:

#This function creates a Star Wars themed Thanksgiving Card
def thanksgivingCard():
  import java.awt.Font as Font                   #Import font
  card = chromakey()                             #Basis for greeting card
  turkey = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//turkey1.jpg")
  turkey = makeNegative(turkey)                  #Make negative image of turkey picture to blend in
  card = pyCopy(turkey, card, 324, 437)          #Apply turkey to card
  str = ['This Thanksgiving,', 'Choose Between', 'The Dark Side', 'or the Light', 'Side of the', 'Turkey!', 'Happy Thanksgiving!']
  myFont = makeStyle("Broadway", Font.BOLD, 34)
  myFont2 = makeStyle("Broadway", Font.BOLD, 42)
  y = 34                                         #Initial y value for text
  x = 0                                          #Horizontal x value
  for t in range(0, 6):                          #Loop for adding text
    addTextWithStyle(card, 424 + x, y, str[t], myFont, white)
    y = y + 34
    x = x + 15
  addTextWithStyle(card, 750, 204, str[6], myFont2, white)
  card = makeOrange(card)                        #Create an orange hue effect
  show(card)
  writePictureTo(card, "D://Downloads//School//CST 205//Week 1 Pictures//GreetingCard.jpg")

#This function takes a green screen image and applies a background to it
def chromakey():
  pica = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//falcon1.jpg")  #Green Screen
  picb = makePicture("D://Downloads//School//CST 205//Week 1 Pictures//darthmonochrome.jpg")   # Background
  pixels = getPixels(pica)
  pixelsB = getPixels(picb)
  for p in pixels:
     r = getRed(p)
     g = getGreen(p)
     b = getBlue(p)
     if (r + b) <= g:
       xA = getX(p)
       yA = getY(p)
       pixB = getPixel(picb, xA, yA)
       newColor = getColor(pixB)
       setColor(p, newColor)
  return(pica)
  
# This function makes the picture have an orange hue
def makeOrange(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    setGreen(p, r * .65)
    setBlue(p, 0)
  repaint (pic)
  return pic
  
# This function creates a simple copy of an image in a larger background with given parameters
def pyCopy(source, target, targetX, targetY):
  oldpic = duplicatePicture(source)
  newpic = duplicatePicture(target)
  x2 = targetX
  for x in range(0, getWidth(oldpic) - 1):
    y2 = targetY
    x2 = x2 + 1
    for y in range(0, getHeight(oldpic) - 1):
      p = getPixel(oldpic, x, y)
      pixeltarget = getPixelAt(newpic, x2, y2)
      newcolor = getColor(p)
      setColor(pixeltarget, newcolor)
      y2 = y2 + 1
  return newpic
  
# This function makes a negative image of the picture
def makeNegative(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    r = 255 - r
    setRed(p, r)
    g = getGreen(p)
    g = 255 - g
    setGreen(p, g)
    b = getBlue(p)
    b = 255 - b
    setBlue(p, b)
  return pic

Line Drawing

































This function creates a black and white drawing like image of a given picture. To achieve this first the image is turned into a black and white image. Then it runs through each pixel and creates a luminaance function using lambda. The luminance is the average of the RGB value for that pixel. It then calculates the luminance to the right of the pixe, below the pixel and for the pixel itself. If the absolute value of the luminance between the right pixel and below pixel is  > 4 and the absolute value of the luminance between the pixel below and the original pixel is  > 4, then its sets the color to black. Otherwise the color gets set to white creating a sketch pencil drawing effect. This function was easy enough to create. I just had to toy with a correct absolute value to achieve the desired effect. Here is the corresponding code:

def lineDwg(pic):
  #turn B&W
  pic = betterBnW(pic)
  picture = duplicatePicture(pic)
  width, height = getWidth(pic) , getHeight(pic)

  for y in xrange(height - 1):
    for x in xrange(width - 1):
    
      px = getPixel(picture, x, y) # original pixel
      right = getPixel(picture, x + 1, y)#right pixel
      below = getPixel(picture, x, y + 1)#below pixel
    
      #get luminance
      luminance = lambda px: (getRed(px) + getBlue(px) + getGreen(px) )/3
    
      LR = luminance(right)#luminance to right pizel
      LB = luminance(below)#luminance below pixel
      LO = luminance(px)#luminance of original pixel
      #pixel edge
      if abs(LR - LO) > 4 and abs(LB - LO) > 4:
        #return b&w image
        setColor(px, black)
      else:
        setColor(px, white)

  show(picture)
  writePictureTo(picture, "D://Downloads//School//CST 205//Week 1 Pictures//lineDwg.jpg")
  
# This function makes a more suitable black and white picture
def betterBnW(picture):
  pic = picture
  pixels = getPixels(pic)
  for p in pixels:
    r = getRed(p)
    g = getGreen(p)
    b = getBlue(p)
    luminace = ((r * .299) + (g * .587) + (b * .114))
    setRed(p, luminace)
    setGreen(p, luminace)
    setBlue(p, luminace)
  return (pic)
  

Wednesday, November 9, 2016

CST 205 Week 2

CST 205 Week 2

The TED talk on the Key to Success being grit was very informative. I have found this to be true in my own life. When there were failures in my life, I can look back and see that a passion and determination were not present at the time which led to failure. With maturity I have learned that "grit" and passion are even more essential to success than intelligence or IQ.

I learned about looping across a range of pixels. Here is how the pseudocode looks for this:

for each x from 0 to x - 1:
    for each y from 0 to y - 1:
        manipulate pixel

or in code

for x in range (0, getWidth(pic)):
    for y in range (0, getHeight(pic)):
        do-stuff-to-pixel(pic, x, y)

The writePictureTo() function allows you to store the manipulated picture in your hard drive. The first variable is the variable for the picture and the second variable is the file location on the hard drive.
In Python you can use the pass statement to skip the body of a conditional statement. This is usually used to keep a placekeeper for a conditional statement to come back to later.

This week I did a lot of photo manipulation using for loops. I found some of the exercises to be challanging and others to be failry easy. I found that a good approach to the challenging problems is to really make a good effort to do thorough pre planning and pseudocode for the exercise. Sometimes I get caught up in the programming and just start without setting up pseudocode. For a harder problem, this can actually make the task last longer. I will adjust my methods for future labs.

Tuesday, November 1, 2016

CST 205 Week 1

CST 205 Week 2

We want to digitize media as a way of preserving it and ease of transferability. Digital data can in theory be copied over and over again without any loss of the original data. Digitization is the process of converting a information into binary code. Digitization occurs by discretization and quantization. Converting a series of digital integers to an approximate analog output is called DA conversion. Some drawbacks of digitization is that there is a loss in quality even if minute compared to the analog source. Also digitization is dependent on technology whereas analog media usually is much easier to produce and store without electricity.
Increasing an images sampling frequency will increase its resolution. Bit depth is the number of bits used for a pixel. A 1 bit image has 2¹ or 2 tones. An 8 bit image has 2⁸ or 256 tones. Dynamic range is the range of tonal difference between the lightest and darkest of the image.

Formulas for File Size
File Size = (height x width x bit depth x dpi²)/8
File Size = (pixel dimensions x bit depth)/8
1 Kilobyte (KB) = 1,024 bytes or 2¹ยบ
1 Megabyte (MB) = 1,024 KB
1 Gigabyte (GB) = 1,024 MB
1 Terabyte (TB) = 1,024 GB

File Types
TIFF- lossless or lossy, big files, used mostly as lossless, used mostly in digital cameras
PNG - lossless, looks for patters in the image to compress the file size; images with large areas of uniform colors, allows for partial transparency
GIF - uses 256 colors, if an image has more colors it compresses to 256 colors, finds patters of colors and creates an abreviations, ie. white, white, white would store as 3 white, for images with less than 256 colors
JPG - discards informationt that the eye is least likely to notice, stored as 24 bit color, most web photographs
RAW - lossless, 3 or 4 times smaller than TIFF, proprietary
BMP - old microsoft format

Python Learning
In Python, comments are made with the # symbol.
To define a function you use, def function_name():
To end the function you enter an empty line
An example of a stack diagram:

I found this week to be pretty straight forwad. I had fun learning about digital media and manipulation of image files. I can't wait to see what the next weeks bring.