예제 #1
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> bool:
     return ImageMethods.norm_rel_l2(
         params[AngleSelectParams.ROT_TR_A_IMG].value,
         params[AngleSelectParams.REF_IMG].value,
     ) <= ImageMethods.norm_rel_l2(
         params[AngleSelectParams.ROT_TR_B_IMG].value,
         params[AngleSelectParams.REF_IMG].value,
     )
예제 #2
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)
예제 #3
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)
예제 #4
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,
     )
예제 #5
0
def _calculate_gaussdiff(image_type: Enum,
                         params: Dict[Enum, Parameter]) -> np.ndarray:
    return ImageMethods.compute_dgfw(
        params[image_type].value,
        params[LogPolParams.GAUSS_DIFF].value,
        params[LogPolParams.WINDOW_WEIGHT].value,
        params[LogPolParams.WINDOW_TYPE].value,
    )
예제 #6
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,
     )
예제 #7
0
 def _value_function_handle(
     params: Dict[Enum, Parameter]
 ) -> Tuple[np.ndarray, np.ndarray, Dict[str, Hashable]]:
     return ImageMethods.recover_rs(
         params[LogPolParams.WARPED_FOURIER_REF_IMG].value,
         params[LogPolParams.WARPED_FOURIER_MOD_IMG].value,
         params[LogPolParams.REF_IMG].value.shape,
         params[LogPolParams.UPSAMPLING].value,
         params[LogPolParams.WINDOW_RADIUS_EXP].value,
     )
예제 #8
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return np.array([
         ImageMethods.max_sinogram_angle(
             params[RadonParams.MOD_IMG].value,
             theta=params[RadonParams.THETA].value,
             exp_filter_val=params[
                 RadonParams.EXPONENTIAL_FILTER_SIGNAL_NOISE].value,
             precision=params[RadonParams.ANGULAR_PRECISION].value,
         ),
         params[RadonParams.ANGULAR_PRECISION].value,
     ])
예제 #9
0
 def _value_function_handle(
         params: Dict[Enum, Parameter]) -> Tuple[int, int, int, int]:
     image = params[LogPolParams.REF_IMG].value
     wrexp = params[LogPolParams.WINDOW_RADIUS_EXP].value
     warp_radius = ImageMethods.compute_warp_radius(min(image.shape), wrexp)
     center = np.array(image.shape) // 2
     r_lower, r_upper = (
         center[0] - warp_radius,
         center[0] + warp_radius,
     )
     c_lower, c_upper = (
         center[1] - warp_radius,
         center[1] + warp_radius,
     )
     return (r_lower, r_upper, c_lower, c_upper)
예제 #10
0
def rot_tr_gen(solvers: Iterable[Solver]) -> Generator[np.ndarray, None, None]:
    """
    Sweep over solver instances and return `tr_x` `tr_y` `tr_err` `rot` `rot_err` `NormRel_L2`

    Parameters
    ----------
    solvers : Iterable
        An iterable of solver instances
    """
    for solv in solvers:
        yield np.array((
            *solv.RECOVERED_TRANSLATION.value,
            *solv.RECOVERED_ROTATION.value,
            ImageMethods.norm_rel_l2(solv.RECOVERED_ROT_TR_IMG.value,
                                     solv.REF_IMG.value),
        ))
예제 #11
0
def rot_scale_tr_gen(
        solvers: Iterable[Solver]) -> Generator[np.ndarray, None, None]:
    """
    Sweep over solver instances and return the rotations, scales and translations

    Parameters
    ----------
    solvers : Iterable
        An iterable of solver instances

    Returns
    -------
    np.array
        Containing `tr_x` `tr_y` `tr_err` `rot` `rot_err` `scale` `scale_err` `NormRel_L2`
    """
    for solv in solvers:
        yield np.array((
            *solv.RECOVERED_TRANSLATION.value,
            *solv.RECOVERED_ROTATION.value,
            *solv.RECOVERED_SCALE.value,
            ImageMethods.norm_rel_l2(solv.RECOVERED_ROT_SCALE_TR_IMG.value,
                                     solv.REF_IMG.value),
        ))
예제 #12
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return ImageMethods.compute_log_polar_tf(
         params[LogPolParams.FOURIER_MOD_IMG].value,
         params[LogPolParams.WINDOW_RADIUS_EXP].value,
     )
예제 #13
0
import numpy as np
import matplotlib.pyplot as plt
import imgreg.data as data
from imgreg.util.methods import ImageMethods

img = np.array(data.mod_img())

# Compute the sinogram using the radon transform
sinogram = ImageMethods.sinogram(img)
plt.imshow(sinogram, aspect=0.1)
plt.show()

# Compute the same sinogram but apply an exponential weighting filter
sinogram = ImageMethods.sinogram(img, exp_filter_val=1000)
plt.imshow(sinogram, aspect=0.1)
plt.show()
예제 #14
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return ImageMethods.abs_diff(
         params[ValidatorParams.IMG].value,
         params[ValidatorParams.REF_IMG].value,
     )
예제 #15
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> float:
     return ImageMethods.norm_rel_l2(
         params[ValidatorParams.IMG].value,
         params[ValidatorParams.REF_IMG].value,
     )
예제 #16
0
 def _value_function_handle(params: Dict[Enum, Parameter]) -> np.ndarray:
     return ImageMethods.compute_afts(
         params[LogPolParams.GAUSS_DIFF_MOD_IMG].value)
예제 #17
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])
예제 #18
0
def request_rts(request, ref_image):
    angle, translation = request.param
    return ImageMethods.compute_rts(ref_image,
                                    angle=angle,
                                    translation=translation)