Beispiel #1
0
def process_tile(ii, reports=None):
    global _SUCCS, _SHIFTS, _ANGLES, _SCALES, _DIFFS
    tile = _TILES[ii]
    image = _IMAGE
    opts = _OPTS
    pos = _POSS[ii]
    try:
        # TODO: Add unittests that zero success result
        #   doesn't influence anything
        with reporting.report_wrapper(reports, ii) as wrapped:
            resdict = process_images((tile, image), opts,
                                     reports=wrapped)
        resdict['tvec'] += pos
        if np.isnan(_DIFFS[0]):
            _DIFFS[0] = resdict["Dangle"]
            _DIFFS[1] = resdict["Dscale"]
            _DIFFS[2] = resdict["Dt"]
    except ValueError:
        # probably incompatible images due to high scale change, so we
        # just add some harmless stuff here and proceed.
        resdict = dict(success=0)
    _distribute_resdict(resdict, ii)
    _SUCCS[ii] = resdict["success"]
    if _SUCCS[ii] > 0:
        # print("%d: succ: %g" % (ii, resdict["success"]))
        # import pylab as pyl
        resdict["tvec"] -= pos
        tosa = ird.transform_img_dict(image, resdict, 0, opts["order"])
        tosa = utils.unextend_by(tosa, opts["extend"])
Beispiel #2
0
def process_tile(ii, reports=None):
    global _SUCCS, _SHIFTS, _ANGLES, _SCALES, _DIFFS
    tile = _TILES[ii]
    image = _IMAGE
    opts = _OPTS
    pos = _POSS[ii]
    try:
        # TODO: Add unittests that zero success result
        #   doesn't influence anything
        with reporting.report_wrapper(reports, ii) as wrapped:
            resdict = process_images((tile, image), opts,
                                     reports=wrapped)
        resdict['tvec'] += pos
        if np.isnan(_DIFFS[0]):
            _DIFFS[0] = resdict["Dangle"]
            _DIFFS[1] = resdict["Dscale"]
            _DIFFS[2] = resdict["Dt"]
    except ValueError:
        # probably incompatible images due to high scale change, so we
        # just add some harmless stuff here and proceed.
        resdict = dict(success=0)
    _distribute_resdict(resdict, ii)
    _SUCCS[ii] = resdict["success"]
    if _SUCCS[ii] > 0:
        # print("%d: succ: %g" % (ii, resdict["success"]))
        # import pylab as pyl
        resdict["tvec"] -= pos
        tosa = ird.transform_img_dict(image, resdict, 0, opts["order"])
        tosa = utils.unextend_by(tosa, opts["extend"])
Beispiel #3
0
def _postprocess_unextend(ims, im2, extend, rcoef=1):
    if rcoef != 1:
        ims = [resample(img, 1.0 / rcoef) for img in ims]
        im2 = resample(im2, 1.0 / rcoef)

    ret = [utils.unextend_by(img, extend) for img in ims + [im2]]
    return ret
Beispiel #4
0
def _postprocess_unextend(ims, im2, extend, rcoef=1):
    if rcoef != 1:
        ims = [resample(img, 1.0 / rcoef) for img in ims]
        im2 = resample(im2, 1.0 / rcoef)

    ret = [utils.unextend_by(img, extend)
           for img in ims + [im2]]
    return ret
Beispiel #5
0
def process_images(ims, opts, tosa=None):
    # lazy import so no imports before run() is really called
    import numpy as np
    from imreg_dft import utils
    from imreg_dft import imreg

    ims = [utils.extend_by(img, opts["extend"]) for img in ims]
    bigshape = np.array([img.shape for img in ims]).max(0)

    ims = filter_images(ims, opts["low"], opts["high"])
    rcoef = opts["resample"]
    if rcoef != 1:
        ims = [resample(img, rcoef) for img in ims]
        bigshape *= rcoef

    # Make the shape of images the same
    ims = [
        utils.embed_to(np.zeros(bigshape) + utils.get_borderval(img, 5), img)
        for img in ims
    ]

    resdict = imreg.similarity(ims[0], ims[1], opts["iters"], opts["order"],
                               opts["constraints"], opts["filter_pcorr"],
                               opts["exponent"])

    im2 = resdict.pop("timg")

    # Seems that the reampling simply scales the translation
    resdict["tvec"] /= rcoef
    ty, tx = resdict["tvec"]
    resdict["tx"] = tx
    resdict["ty"] = ty
    resdict["imgs"] = ims
    tform = resdict

    if tosa is not None:
        tosa[:] = ird.transform_img_dict(tosa, tform)

    if rcoef != 1:
        ims = [resample(img, 1.0 / rcoef) for img in ims]
        im2 = resample(im2, 1.0 / rcoef)
        resdict["Dt"] /= rcoef

    resdict["unextended"] = [
        utils.unextend_by(img, opts["extend"]) for img in ims + [im2]
    ]

    return resdict
Beispiel #6
0
    def testExtend(self):
        what = np.random.random((20, 11))
        whaty = what.shape[0]
        what[:] += np.arange(whaty, dtype=float)[:, np.newaxis] * 5 / whaty
        dftscore0 = self._dftscore(what)
        dsts = (2, 3, 4)
        for dst in dsts:
            ext = utils.extend_by(what, dst)

            # Bigger distance should mean better "DFT score"
            dftscore = self._dftscore(ext)
            self.assertLess(dftscore, dftscore0 * 1.1)
            dftscore0 = dftscore

            undone = utils.unextend_by(ext, dst)
            self.assertEqual(what.shape, undone.shape)
Beispiel #7
0
    def testExtend(self):
        what = np.random.random((20, 11))
        whaty = what.shape[0]
        what[:] += np.arange(whaty, dtype=float)[:, np.newaxis] * 5 / whaty
        dftscore0 = self._dftscore(what)
        dsts = (2, 3, 4)
        for dst in dsts:
            ext = utils.extend_by(what, dst)

            # Bigger distance should mean better "DFT score"
            dftscore = self._dftscore(ext)
            self.assertLess(dftscore, dftscore0 * 1.1)
            dftscore0 = dftscore

            undone = utils.unextend_by(ext, dst)
            self.assertEqual(what.shape, undone.shape)
Beispiel #8
0
def process_images(ims, opts, tosa=None):
    # lazy import so no imports before run() is really called
    import numpy as np
    from imreg_dft import utils
    from imreg_dft import imreg

    ims = [utils.extend_by(img, opts["extend"]) for img in ims]
    bigshape = np.array([img.shape for img in ims]).max(0)

    ims = filter_images(ims, opts["low"], opts["high"])
    rcoef = opts["resample"]
    if rcoef != 1:
        ims = [resample(img, rcoef) for img in ims]
        bigshape *= rcoef

    # Make the shape of images the same
    ims = [utils.embed_to(np.zeros(bigshape) + utils.get_borderval(img, 5), img)
           for img in ims]

    resdict = imreg.similarity(
        ims[0], ims[1], opts["iters"], opts["order"], opts["constraints"],
        opts["filter_pcorr"], opts["exponent"])

    im2 = resdict.pop("timg")

    # Seems that the reampling simply scales the translation
    resdict["tvec"] /= rcoef
    ty, tx = resdict["tvec"]
    resdict["tx"] = tx
    resdict["ty"] = ty
    resdict["imgs"] = ims
    tform = resdict

    if tosa is not None:
        tosa[:] = ird.transform_img_dict(tosa, tform)

    if rcoef != 1:
        ims = [resample(img, 1.0 / rcoef) for img in ims]
        im2 = resample(im2, 1.0 / rcoef)
        resdict["Dt"] /= rcoef

    resdict["unextended"] = [utils.unextend_by(img, opts["extend"])
                             for img in ims + [im2]]

    return resdict
Beispiel #9
0
def _postprocess_unextend(ims, im2, extend):
    ret = [utils.unextend_by(img, extend) for img in ims + [im2]]
    return ret