Skip to content
Snippets Groups Projects
Commit 8f767e60 authored by z.boztoprak's avatar z.boztoprak
Browse files

update: use open cv for faster computation

parent 7347ab4b
No related branches found
No related tags found
1 merge request!1add: resizing of modalities
Pipeline #160774 passed
......@@ -2,7 +2,6 @@ from typing import Any, Sequence, Union
import numpy as np
import cv2
from skimage.transform import resize
from .functions import mod2cplx, cplx2mod, mods2dft, dft2mods, fill_missing_mod, to_array
......@@ -340,8 +339,8 @@ def resize_mods(
dir: np.ndarray,
ret: np.ndarray,
dsize: Sequence[int],
interpolation: int = 3,
anti_aliasing: bool = True
sigma: float,
interpolation: int = 3
):
"""
Resizes the 3D-PLI Modalities.
......@@ -356,18 +355,16 @@ def resize_mods(
Retardation of the signal of shape H x W
:param dsize:
Shape of the output modalities as (width, height)
:param sigma: float
Standard deviation for Gaussian filtering.
:param interpolation: int
Interpolation mode.
0: Nearest-neighbor
1: Bi-linear (default)
2: Bi-quadratic
3: Bi-cubic
4: Bi-quartic
5: Bi-quintic
:param anti_aliasing: bool
Whether to apply Gaussian filter prior to downsampling.
0: cv2.INTER_NEAREST
1: cv2.INTER_LINEAR
2: cv2.INTER_CUBIC
3: cv2.INTER_AREA
4: cv2.INTER_LANCZOS4
:return:
trans_resized: np.ndarray
......@@ -383,8 +380,11 @@ def resize_mods(
# Transform modalities in joint dft representation
dft = mods2dft(trans, dir, ret)
# apply gaussian blur for anti-aliasing before resizing
dft = cv2.GaussianBlur(dft, (0,0), sigma)
# Rescale the dft representation
dft_resized = resize(dft, dsize, order=interpolation, anti_aliasing=anti_aliasing)
dft_resized = cv2.resize(dft, dsize, interpolation=interpolation)
trans_resized, dir_resized, ret_resized = dft2mods(dft_resized)
......
  • a.oberstrass @a.oberstrass ·
    Maintainer

    Very nice if this speedups this function. Would it be an idea to use the skimage default behaviour for the case sigma is not provided but anti_aliasing = True and set sigma as:

    By default, this value is chosen as (s - 1) / 2 where s is the downsampling factor, where s > 1. For the up-size case, s < 1, no anti-aliasing is performed prior to rescaling.

    In this way, one does not need to calculate the right sigma all the time

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment