Пример #1
0
def testComputeTransformedBBox():
    im1=io.imread('stata/stata-1.png')
    im2=io.imread('stata/stata-2.png')
    pointList1=[np.array([209, 218, 1]), np.array([425, 300, 1]), np.array([209, 337, 1]), np.array([396, 336, 1])]
    pointList2=[np.array([232, 4, 1]), np.array([465, 62, 1]), np.array([247, 125, 1]), np.array([433, 102, 1])]
    listOfPairsS=zip(pointList1, pointList2)
    HS=a6.computeHomography(listOfPairsS)
    shape = np.shape(im2)
    print a6.computeTransformedBBox(shape, HS)
Пример #2
0
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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
def applyHomographyFast(source, out, H, weights, weightIm, abrupt=False):
    # takes the image source, warps it by the homography H, and adds it to the composite out.
    # This version should only iterate over the pixels inside the bounding box of source's image in out.
    bbox = a6.computeTransformedBBox(source.shape, H)
    Hinv = linalg.inv(H)
    for y in xrange(bbox[0][0], bbox[1][0]):
        for x in xrange(bbox[0][1], bbox[1][1]):
            yp, xp, w = Hinv.dot(np.array([y, x, 1.0]))
            yp, xp = (yp / w, xp / w)
            if yp >= 0 and yp < source.shape[0] and xp >= 0 and xp < source.shape[1]:
                if abrupt and weights[yp, xp, 0] > weightIm[y, x, 0]:
                    weightIm[y, x] = weights[yp, xp]
                    out[y, x] = weights[yp, xp] * a6.interpolateLin(source, yp, xp)
                elif not abrupt:
                    weightIm[y, x] += weights[yp, xp]
                    out[y, x] += weights[yp, xp] * a6.interpolateLin(source, yp, xp)
Пример #6
0
def applyHomographyFast_blended(source, out, H, out_weight, weight_map, onlyHighestWeight=False):
    """Takes the image source, warps it by the homography H, and adds it to the composite out.
    This version should only iterate over the pixels inside the bounding box of source's image in out. """

    bbox = a6.computeTransformedBBox(np.shape(source), H)
    for y in xrange(bbox[0][0], bbox[1][0]):
        for x in xrange(bbox[0][1], bbox[1][1]):
            (yp, xp, wp) = np.dot(linalg.inv(H), np.array([y, x, 1]))
            (ypp, xpp) = (yp / wp, xp / wp)
            if a6.within_bounds(source, ypp, xpp):
                if not onlyHighestWeight:
                    out[y, x] += a6.interpolateLin(source, ypp, xpp) * weight_map[ypp, xpp]
                    out_weight[y, x] += weight_map[ypp, xpp]
                elif np.sum(weight_map[ypp, xpp]) > np.sum(out_weight[y, x]):
                    out[y, x] = a6.interpolateLin(source, ypp, xpp) * weight_map[ypp, xpp]
                    out_weight[y, x] = weight_map[ypp, xpp]
                else:
                    pass
Пример #7
0
def applyHomographyFast(source, out, H, weights, weightIm, abrupt=False):
    # takes the image source, warps it by the homography H, and adds it to the composite out.
    # This version should only iterate over the pixels inside the bounding box of source's image in out.
    bbox = a6.computeTransformedBBox(source.shape, H)
    Hinv = linalg.inv(H)
    for y in xrange(bbox[0][0], bbox[1][0]):
        for x in xrange(bbox[0][1], bbox[1][1]):
            yp, xp, w = Hinv.dot(np.array([y, x, 1.0]))
            yp, xp = (yp / w, xp / w)
            if yp >= 0 and yp < source.shape[
                    0] and xp >= 0 and xp < source.shape[1]:
                if abrupt and weights[yp, xp, 0] > weightIm[y, x, 0]:
                    weightIm[y, x] = weights[yp, xp]
                    out[y, x] = weights[yp, xp] * a6.interpolateLin(
                        source, yp, xp)
                elif not abrupt:
                    weightIm[y, x] += weights[yp, xp]
                    out[y, x] += weights[yp, xp] * a6.interpolateLin(
                        source, yp, xp)