コード例 #1
0
 def test_compute_rts(self, retina, angle_scale_translation, expected_err,
                      rtol):
     angle, scale, translation = angle_scale_translation
     mod_img = ImageMethods.compute_rts(retina,
                                        angle=angle,
                                        scale=scale,
                                        translation=translation)
     rec_img = ImageMethods.compute_rts(mod_img,
                                        angle=angle,
                                        scale=scale,
                                        translation=translation,
                                        inverse=True)
     assert m.isclose(np.linalg.norm(retina - rec_img),
                      expected_err,
                      rel_tol=rtol)
コード例 #2
0
def image_save_back_tf(rot_tr_arr: np.ndarray, fnames: Sequence[str],
                       src_path: str, dest_path: str):
    """
    Creates backtransformed images

    For an external program that compares images `*_A.*` with `*_B.*` this prepares images
    such that::

      test00001.jpg -> test00001_A.png
      test00021.jpg -> TR -> test00001_B.png, test00021_A.png

      test00221.jpg -> TR -> test00201_B.png, test00221_A.png
      test00241.jpg -> TR -> test00221_B.png

    where TR denotes the backtransformation.
    """
    for i, fname in enumerate(fnames):
        if i == 0:
            pass
        src_arr = np.array(Image.open(src_path + "/" + fname))
        dest_arr = ImageMethods.compute_rts(
            src_arr,
            angle=rot_tr_arr[i][3],
            translation=rot_tr_arr[i][:2],
            inverse=True,
        )
        dest_img = Image.fromarray(dest_arr).convert("L")
        if i != len(fnames) - 1:
            out_a = dest_path + "/" + fname.split(".")[0] + "_A.png"
            dest_img.save(out_a)
        if i != 0:
            out_b = dest_path + "/" + fnames[i - 1].split(".")[0] + "_B.png"
            dest_img.save(out_b)
コード例 #3
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return ImageMethods.compute_rts(
         params[LogPolParams.MOD_IMG].value,
         angle=params[LogPolParams.RECOVERED_ROTATION].value[0],
         scale=params[LogPolParams.RECOVERED_SCALE].value[0],
         translation=params[LogPolParams.RECOVERED_TRANSLATION].value[:-1],
         inverse=True,
     )
コード例 #4
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return ImageMethods.compute_rts(
         params[AngleSelectParams.IMG].value,
         angle=params[AngleSelectParams.ANGLE_B].value,
         scale=1,
         translation=params[AngleSelectParams.TRANSLATION_B].value[:-1],
         inverse=True,
         preserve_range=True,
     )
コード例 #5
0
import numpy as np
import imgreg.data as data
from imgreg.models.validator import Validator
from imgreg.util.methods import ImageMethods

ref_img = np.array(data.ref_img())

# modify the image using an affine transformation
img = ImageMethods.compute_rts(ref_img, angle=2, translation=(6, 2))

# Create the model:
val = Validator(img, ref_img)

# The ImageParameters of the model have matplotlib support via the display function:
val.display([val.ABSOLUTE_DIFFERENCE_IMG, val.SQUARED_DIFFERENCE_IMG])

# Increase the overlap to the reference image
val.IMG.value = ImageMethods.compute_rts(ref_img, angle=1, translation=(1, 2))

# Note how the difference images show less pronounced differences with increased overlap
val.display([val.ABSOLUTE_DIFFERENCE_IMG, val.SQUARED_DIFFERENCE_IMG])
コード例 #6
0
def request_rts(request, ref_image):
    angle, translation = request.param
    return ImageMethods.compute_rts(ref_image,
                                    angle=angle,
                                    translation=translation)