Exemple #1
0
def makeCollage(pics = []):

  # Get 8 images total if there aren't at least 8 provided
  picCount = len(pics)
  if picCount < 8:
    for i in range (picCount, 8):
      pics.append(makePicture(pickAFile())) 
  
  # Shuffle the images
  shuffle(pics)
  
  # Create blank 8.5"x11" canvas
  collage = makeEmptyPicture(816,1056)
  show(collage)
  
  # Determine how many rows and columns to use
  columns = floor(sqrt(picCount))
  rows = int(ceil(picCount / columns))
  remainder = picCount - (rows * columns)
  
  # Determine width of columns and height of rows
  columnWidth = ceil(getWidth(collage) / columns)
  rowHeight = ceil(getHeight(collage) / rows)
  
  # Create list of transformation functions from previous labs
  collageFunctions = [lessRed,moreRed,roseColoredGlasses,lightenUp,makeNegative,betterBnW,halfBetter, \
                      mirrorVertical,mirrorTop,mirrorBottom,mirrorQuadruple,sepia,artify,noBlue]
    
  # Resize each image, apply a random transformation, add to the collage
  for i in range (0, picCount):
  
    # Determine collage row number
    currentRow = int(i / columns)
    
    # For the last row, recalculate the number of required columns for remaining images
    if currentRow == rows - 1 and i % columns == 0:
      columnWidth = ceil(getWidth(collage) / (columns + remainder))      
      
    # Get starting coordinates for image
    currentY = int(currentRow * rowHeight)
    currentX = int((i % columns) * columnWidth)
  
    # Copy and resize image
    pic = resize(pics[i],columnWidth,rowHeight)
    
    # Get transformation function index
    index = i % len(collageFunctions)
    # Shuffle transformation functions each time through list
    if index == 0:
      shuffle(collageFunctions)
    # Apply transformation
    collageFunctions[index](pic)
     
    # Add image to collage
    pyCopy(pic,collage,currentX,currentY)
      
    # Update when each pic is added to make it seem faster
    repaint(collage)
  
  return collage
Exemple #2
0
    def __getitem__(self, idx):
        idx = np.random.randint(0, len(self.names))
        name = self.names[idx]
        image = Image.open("Dataset/ColoredProcessedImages/" +
                           self.names[idx] + ".png")
        temp = []
        for i in range(len(self.joints[name])):
            temp.append(
                [int(self.joints[name][i][0]),
                 int(self.joints[name][i][1])])
        s_image, s_temp = transformations.resize(image, temp)
        n_image, n_temp = self.trans[random.randrange(0, len(self.trans))](
            s_image, s_temp)
        orig_image = np.array(n_image)
        n_image = self.norm(n_image)
        #n_image, n_temp = self.trans[random.randrange(0, len(self.trans))](image,temp)
        r_image = np.array(n_image)
        temp = []

        sample = {
            'image': r_image,
            #'joints': temp,
            'joints': n_temp,
            'name': name
        }

        if self.transform:
            sample = self.hog(sample)

        return name, r_image, np.array(n_temp), orig_image
Exemple #3
0
def thanksgivingCard():

  # Create blank card, get dimensions
  card = makeEmptyPicture(96*5,96*7) # 96 ppi
  cardWidth = getWidth(card)
  cardHeight = getHeight(card)
  
  # Add background image to card
  # Make sure LAB_DIR is set to the correct directory
  background = makePicture(LAB_DIR + "\\Card\\background.jpg")
  background = resize(background,cardWidth,cardHeight)
  pyCopy(background,card,0,0)
  
  # Get green-screened wishbone picture
  # Make sure LAB_DIR is set to the correct directory
  wishbone = makePicture(LAB_DIR + "\\Card\\wishboneGreen.jpg")
  wishbone = resize(wishbone,cardWidth,cardHeight/3)
  
  # Replace wishbone background with dinner picture
  # Make sure LAB_DIR is set to the correct directory
  dinner = makePicture(LAB_DIR + "\\Card\\dinner.jpg")
  wishbone = chromakey(wishbone,dinner)
  
  # Add wishbone/dinner image to card
  wishboneY = cardHeight/5
  pyCopy(wishbone,card,0,wishboneY)
  
  # Add text to card
  fontSize = int(cardHeight * 0.1)
  fontStyle = makeStyle(serif,italic+bold,fontSize)
  text = ["Wishing you a","very happy","Thanksgiving!"]
  for t in range(0,len(text)):
    addTextWithStyle(card,int((cardWidth-(len(text[t])*fontSize*.5))/2), \
                     int((wishboneY + getHeight(wishbone) + fontSize) + t * fontSize * 1.25), \
                     text[t], fontStyle,orange)
                                                       
  return card
  
  
Exemple #4
0
def chromakey(greenScreen,newBackground):

  # Copy original pic to alter, adjust background size to fit
  pic = simpleCopy(greenScreen)
  picWidth = getWidth(pic)
  picHeight = getHeight(pic)
  resizedBackground = resize(newBackground,getWidth(pic),getHeight(pic))
  
  # If a pixel is green within a certain threshold, replace with new background color
  for x in range (0, picWidth):
    for y in range (0, picHeight):
      p = getPixel(pic,x,y)
      r = getRed(p)
      g = getGreen(p)
      b = getBlue(p)
      # If color is a shade of green...
      if (g - r) > 20 and (g - b ) > 20:
        # Change pixel color to new background color
        setColor(p,getColor(getPixel(resizedBackground,x,y)))
        
  return pic