def compositeNImages(listOfImages, listOfH, weights, abrupt=False): # Computes the composite image. listOfH is of the form returned by computeNHomographies. # Hint: You will need to deal with bounding boxes and translations again in this function. bbox = a6.computeTransformedBBox(listOfImages[0].shape, listOfH[0]) for img, H in zip(listOfImages, listOfH): currentbbox = a6.computeTransformedBBox(img.shape, H) bbox = a6.bboxUnion(currentbbox, bbox) trans = a6.translate(bbox) out = np.zeros((bbox[1][0] - bbox[0][0], bbox[1][1] - bbox[0][1], 3)) weightIm = np.zeros((out.shape[0], out.shape[1], 3)) for img, H in zip(listOfImages, listOfH): applyHomographyFast(img, out, trans.dot(H), weights, weightIm, abrupt) weightIm[weightIm == 0] = np.min(weightIm[weightIm.nonzero()]) # no zero in denominators return out / weightIm
def compositeNImages(listOfImages, listOfH, weights, abrupt=False): # Computes the composite image. listOfH is of the form returned by computeNHomographies. # Hint: You will need to deal with bounding boxes and translations again in this function. bbox = a6.computeTransformedBBox(listOfImages[0].shape, listOfH[0]) for img, H in zip(listOfImages, listOfH): currentbbox = a6.computeTransformedBBox(img.shape, H) bbox = a6.bboxUnion(currentbbox, bbox) trans = a6.translate(bbox) out = np.zeros((bbox[1][0] - bbox[0][0], bbox[1][1] - bbox[0][1], 3)) weightIm = np.zeros((out.shape[0], out.shape[1], 3)) for img, H in zip(listOfImages, listOfH): applyHomographyFast(img, out, trans.dot(H), weights, weightIm, abrupt) weightIm[weightIm == 0] = np.min( weightIm[weightIm.nonzero()]) # no zero in denominators return out / weightIm
def compositeNImages_blended(listOfImages, listOfHomographies, weights, onlyHighestWeight=False): bbox = a6.computeTransformedBBox(np.shape(listOfImages[0]), listOfHomographies[0]) for (i, H) in enumerate(listOfHomographies): bboxI = a6.computeTransformedBBox(np.shape(listOfImages[i]), H) bbox = a6.bboxUnion(bboxI, bbox) height = bbox[1][0] - bbox[0][0] width = bbox[1][1] - bbox[0][1] out = np.zeros([height, width, 3]) out_weight = np.zeros([height, width, 3]) translation = a6.translate(bbox) for i in xrange(len(listOfImages)): applyHomographyFast_blended( listOfImages[i], out, np.dot(translation, listOfHomographies[i]), out_weight, weights, onlyHighestWeight ) out_weight[out_weight == 0] = 1e-12 return out / out_weight