Tuesday, November 10, 2015

Week 2 or is it 3? in cool python class


So we're on week 3! There wasn't much going on this week. It was a lot of following along with different requests to write image manipulation functions. I didn't really read along with what was going to be expected in the later assignments and focused on creating the ultimate collage as soon as I saw that was an assignment. This lead to upgrading the requested pyCopy function which pastes one pic on to another to be pyCopyA which let me select a color to be an alpha channel along with a precision.  The key thing here is to check that you are not going to exceed the top, bottom, left, and right sides of the picture while copying pixels. I should really hit some kind of tripping point so that it swings back around like a type writer when it hits the end instead of continuing to check pixels. But it worked out nicely I think even if it runs slowly. What is also nice is that using sublime text editor I get more autopopulation of function names etc so I don't have to refer to online help as much.

# Function: python copy with alpha, copy source image to target image and remove transparent pixels
# Params: source image, target image, target x for 0, target y for 0
# Returns: Resized picture
def pyCopyA(source, target, targetX, targetY, alphaR, alphaG, alphaB, precision):
  targetWidth = target.getWidth()
  targetHeight = target.getHeight()

  for y in range( 0, source.getHeight() ): # work from top to bottom
    if (y + targetY < targetHeight) and (y + targetY > 0): #Y range check so we can go crazy and not worry
      for x in range( 0, source.getWidth() ):
        if (x + targetX < targetWidth) and (x + targetX > 0): #X range check so we can go crazy and not worry
          sourcePixel = getPixel(source, x, y)
          sourceColor = getColor(sourcePixel)
          if ( abs(sourceColor.getRed() - alphaR) + abs(sourceColor.getBlue() - alphaB) + abs(sourceColor.getGreen() - alphaG) ) > precision:
            destPixel = getPixel(target, x + targetX, y + targetY)
            destPixel.setColor(sourceColor)        

Then it turned out we should do some green screen pictures which was conveinent because adding this functionality was non-negotiable for making a cool collage. So I was good to go. I think what I am getting most out of this is really just more time spent writing functions etc. The actual content of the functions doesn't really matter much to me because you will always find cool algorithms all around you that you can mess with and convert to any language you like.

My top learning objective this week was finding an article about low power wide area networks. These low data rate radios use low power but can go long distances which is what I would like to use in a capstone project if that works out. The action item there is to purchase radios and try them out. There was also another interesting article about people implanting LED light arrays under their skin. I think that would be another good application for these kinds of LPWAN modules to connect people to their off grid communication networks. Powering these devices could be a bit akward though but cutting them out every year would be a hassle. So by getting in a better software groove some interesting opportunities should open up as radio modules continue to get better. Google also released some tensor flow AI open source project but I have no idea what to do with that.

No comments:

Post a Comment