示例#1
0
def collapse(lapl_pyr):
  '''Reconstruct the image based on its laplacian pyramid.

  lapl_pyr - a laplacian pyramid, as constructed by the lapl_pyramid function, or
             returned by the blend function.

  output - an image of the same shape as the base layer of the pyramid and dtype
           float.

  Note: sometimes expand will return an image that is larger than the next layer.
  In this case, you should crop the expanded image down to the size of the next
  layer.

  For example, expanding a layer of size 3x4 will result in an image of size 6x8.
  If the next layer is of size 5x7, crop the expanded image to size 5x7.
  '''
  output = None
  # Insert your code here ------------------------------------------------------
  while len(lapl_pyr) > 1:
    first = part0.expand(lapl_pyr[-1])
    second = lapl_pyr[-2]
    rows_expanded, cols_expanded = first.shape
    rows, cols = second.shape
    if rows_expanded > rows:
      first = first[:-1,:]
    if cols_expanded > cols:
      first = first[:,:-1]
    lapl_pyr = lapl_pyr[:-2]
    lapl_pyr.append(first + second)
  output = lapl_pyr[0]
  # ----------------------------------------------------------------------------
  return output
示例#2
0
文件: part2.py 项目: hliang/compphoto
def collapse(lapl_pyr):
  '''Reconstruct the image based on its laplacian pyramid.

  lapl_pyr - a laplacian pyramid, as constructed by the lapl_pyramid function, or
             returned by the blend function.

  output - an image of the same shape as the base layer of the pyramid and dtype
           float.

  Note: sometimes expand will return an image that is larger than the next layer.
  In this case, you should crop the expanded image down to the size of the next
  layer.

  For example, expanding a layer of size 3x4 will result in an image of size 6x8.
  If the next layer is of size 5x7, crop the expanded image to size 5x7.
  '''
  output = None
  # Insert your code here ------------------------------------------------------
  for i in range(len(lapl_pyr)-1, 0, -1):
    # expand layer k and add to layer k-1
    (expand_to_r, expand_to_c) = (lapl_pyr[i-1].shape[0], lapl_pyr[i-1].shape[1])
    lapl_pyr[i-1] = part0.expand(lapl_pyr[i])[0:expand_to_r, 0:expand_to_c] + lapl_pyr[i-1]
  # only base layer should be returned
  output = lapl_pyr[0]
  # ----------------------------------------------------------------------------
  return output
示例#3
0
def collapse(lapl_pyr):
  '''Reconstruct the image based on its laplacian pyramid.

  lapl_pyr - a laplacian pyramid, as constructed by the lapl_pyramid function, or
             returned by the blend function.

  output - an image of the same shape as the base layer of the pyramid and dtype
           float.

  Note: sometimes expand will return an image that is larger than the next layer.
  In this case, you should crop the expanded image down to the size of the next
  layer.

  For example, expanding a layer of size 3x4 will result in an image of size 6x8.
  If the next layer is of size 5x7, crop the expanded image to size 5x7.
  '''

  output = np.zeros(lapl_pyr[0].shape, dtype = 'float')
  print lapl_pyr , output
  l = len(lapl_pyr)
  output = lapl_pyr[l-1]
  for i in range(l-1, 0, -1):
    expand_image = part0.expand(output)
    if (lapl_pyr[i-1].shape[0] != expand_image.shape[0] ):
        expand_image = expand_image[0:lapl_pyr[i-1].shape[0],:]
    if (lapl_pyr[i-1].shape[1] != expand_image.shape[1] ):
        expand_image = expand_image[:, 0:lapl_pyr[i-1].shape[1]]
    output = expand_image + lapl_pyr[i-1]
  return output
示例#4
0
文件: part1.py 项目: hliang/compphoto
def lapl_pyramid(gauss_pyr):
  '''Construct a laplacian pyramid from the gaussian pyramid, of height levels.

  gauss_pyr - a gaussian pyramid as returned by your gauss_pyramid function.

  output - a laplacian pyramid of the same height as gauss_pyr. This pyramid
           should be represented in the same way as guass_pyr - as a list of
           arrays. Every element of the list now corresponds to a layer of the 
           laplacian pyramid, containing the difference between two layers of 
           the gaussian pyramid. 

           output[k] = gauss_pyr[k] - expand(gauss_pyr[k+1])

           The last element of output should be identical to the last layer of
           the input pyramid.

  Note: sometimes the size of the expanded image will be larger than the given
  layer. You should crop the expanded image to match in shape with the given
  layer.

  For example, if my layer is of size 5x7, reducing and expanding will result
  in an image of size 6x8. In this case, crop the expanded layer to 5x7.
  '''
  output = []
  # Insert your code here ------------------------------------------------------
  for k in range(len(gauss_pyr)-1):
    layer = gauss_pyr[k] - part0.expand(gauss_pyr[k+1])[0:gauss_pyr[k].shape[0], 0:gauss_pyr[k].shape[1]]
    output.append(layer)
  output.append(gauss_pyr[-1])
  # ----------------------------------------------------------------------------
  return output
示例#5
0
def collapse(lapl_pyr):
    '''Reconstruct the image based on its laplacian pyramid.

  lapl_pyr - a laplacian pyramid, as constructed by the lapl_pyramid function, or
             returned by the blend function.

  output - an image of the same shape as the base layer of the pyramid and dtype
           float.

  Note: sometimes expand will return an image that is larger than the next layer.
  In this case, you should crop the expanded image down to the size of the next
  layer.

  For example, expanding a layer of size 3x4 will result in an image of size 6x8.
  If the next layer is of size 5x7, crop the expanded image to size 5x7.
  '''

    output = np.zeros(lapl_pyr[0].shape, dtype='float')
    print lapl_pyr, output
    l = len(lapl_pyr)
    output = lapl_pyr[l - 1]
    for i in range(l - 1, 0, -1):
        expand_image = part0.expand(output)
        if (lapl_pyr[i - 1].shape[0] != expand_image.shape[0]):
            expand_image = expand_image[0:lapl_pyr[i - 1].shape[0], :]
        if (lapl_pyr[i - 1].shape[1] != expand_image.shape[1]):
            expand_image = expand_image[:, 0:lapl_pyr[i - 1].shape[1]]
        output = expand_image + lapl_pyr[i - 1]
    return output
示例#6
0
def lapl_pyramid(gauss_pyr):
  '''Construct a laplacian pyramid from the gaussian pyramid, of height levels.

  gauss_pyr - a gaussian pyramid as returned by your gauss_pyramid function.

  output - a laplacian pyramid of the same height as gauss_pyr. This pyramid
           should be represented in the same way as guass_pyr - as a list of
           arrays. Every element of the list now corresponds to a layer of the
           laplacian pyramid, containing the difference between two layers of
           the gaussian pyramid.

           output[k] = gauss_pyr[k] - expand(gauss_pyr[k+1])

           The last element of output should be identical to the last layer of
           the input pyramid.

  Note: sometimes the size of the expanded image will be larger than the given
  layer. You should crop the expanded image to match in shape with the given
  layer.

  For example, if my layer is of size 5x7, reducing and expanding will result
  in an image of size 6x8. In this case, crop the expanded layer to 5x7.
  '''
  output = [[] for i in range(len(gauss_pyr))]
  for i in range(0, len(gauss_pyr)-1):
    gauss_image = gauss_pyr[i]
    expand_image = part0.expand(gauss_pyr[i+1])
    if (gauss_image.shape[0] != expand_image.shape[0] ):
        expand_image = expand_image[0:gauss_image.shape[0],:]
    if (gauss_image.shape[1] != expand_image.shape[1] ):
        expand_image = expand_image[:, 0:gauss_image.shape[1]]
    output[i] = gauss_image - expand_image
  output[len(gauss_pyr)-1] = gauss_pyr[len(gauss_pyr)-1]

  # Insert your code here ------------------------------------------------------

  # ----------------------------------------------------------------------------
  return output
def lapl_pyramid(gauss_pyr):
    '''Construct a laplacian pyramid from the gaussian pyramid, of height levels.

  gauss_pyr - a gaussian pyramid as returned by your gauss_pyramid function.

  output - a laplacian pyramid of the same height as gauss_pyr. This pyramid
           should be represented in the same way as gauss_pyr - as a list of
           arrays. Every element of the list now corresponds to a layer of the
           laplacian pyramid, containing the difference between two layers of
           the gaussian pyramid.

           output[k] = gauss_pyr[k] - expand(gauss_pyr[k+1])

           The last element of output should be identical to the last layer of
           the input pyramid.

  Note: sometimes the size of the expanded image will be larger than the given
  layer. You should crop the expanded image to match in shape with the given
  layer.

  For example, if my layer is of size 5x7, reducing and expanding will result
  in an image of size 6x8. In this case, crop the expanded layer to 5x7.
  '''
    output = []
    # Insert your code here ------------------------------------------------------
    for l in xrange(len(gauss_pyr) - 1):
        expanded_level = part0.expand(gauss_pyr[l + 1])
        rows, cols = gauss_pyr[l].shape
        rows_expanded, cols_expanded = expanded_level.shape
        if rows_expanded > rows:
            expanded_level = expanded_level[:-1, :]
        if cols_expanded > cols:
            expanded_level = expanded_level[:, :-1]
        output.append(gauss_pyr[l] - expanded_level)
    output.append(gauss_pyr[-1])
    # ----------------------------------------------------------------------------
    return output
示例#8
0
def lapl_pyramid(gauss_pyr):
  '''Construct a laplacian pyramid from the gaussian pyramid, of height levels.

  gauss_pyr - a gaussian pyramid as returned by your gauss_pyramid function.

  output - a laplacian pyramid of the same height as gauss_pyr. This pyramid
           should be represented in the same way as guass_pyr - as a list of
           arrays. Every element of the list now corresponds to a layer of the 
           laplacian pyramid, containing the difference between two layers of 
           the gaussian pyramid. 

           output[k] = gauss_pyr[k] - expand(gauss_pyr[k+1])

           The last element of output should be identical to the last layer of
           the input pyramid.

  Note: sometimes the size of the expanded image will be larger than the given
  layer. You should crop the expanded image to match in shape with the given
  layer.

  For example, if my layer is of size 5x7, reducing and expanding will result
  in an image of size 6x8. In this case, crop the expanded layer to 5x7.
  '''
  output = []
  # Insert your code here ------------------------------------------------------
  print "STARTING MY CODE"
  output = [(np.zeros((5,), dtype=np.float)) for i in range(len(gauss_pyr))]
  #part0.expand(gauss_pyr[i+1])[:-1,:]
  print "SIZE:"
  print len(output)
  for i in range(len(output)):
    if(i+1<len(output)):
      print i+1
      print "Shape"
      print gauss_pyr[i].shape
      print gauss_pyr[i].shape[0]
      print gauss_pyr[i].shape[1]
      a = part0.expand(gauss_pyr[i+1])#[:-1,:]
      b = gauss_pyr[i]
      print a
      print b
      #print np.append(a,b,axis=0)
      print a.shape
      print b.shape
      if b.shape <> a.shape:
        print "Doing Work"
        x, y = b.shape
        a = a[:x,:y]
      print a
      #c = np.vstack[a,b]
      #print c
      output[i]=b-a
    else:#(i==len(gauss_pyr)-1):
      print "My Pramid"
      print gauss_pyr[i]
      output[i]=gauss_pyr[i]
     #else:
       #output[i]=part0.expand(gauss_pyr[i+1])[:-1,:]
  print "END"
  print output
  print "END MY CODE"
  # ----------------------------------------------------------------------------
  return output
示例#9
0
def lapl_expand(image, desired_shape):
  attempt = part0.expand(image)
  if attempt.shape == desired_shape:
    return attempt
  return attempt[0:desired_shape[0], 0:desired_shape[1]]