Skip to content

Commit

Permalink
all tests pass. need to add more tests for test_cavity, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Nov 18, 2023
1 parent 9ccfd44 commit b4dbb0a
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 167 deletions.
16 changes: 8 additions & 8 deletions openptv_python/correspondences.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .epi import Coord2d, epi_mm
from .find_candidate import find_candidate
from .parameters import ControlPar, VolumePar
from .tracking_frame_buf import Frame, Target, TargetArray, n_tupel
from .tracking_frame_buf import Frame, Target, n_tupel

# @dataclass
# class Correspond:
Expand Down Expand Up @@ -53,7 +53,7 @@ def safely_allocate_target_usage_marks(
# Check if any of the allocations failed.
for cam in range(num_cams):
if tusage[cam] is None:
return None
return [] # was None

return tusage

Expand All @@ -74,27 +74,27 @@ def safely_allocate_adjacency_lists(
num_cams: int, target_counts: List[int]
) -> List[List[List[Correspond]]]:
"""Allocate adjacency lists."""
lists = [[None for _ in range(num_cams)] for _ in range(num_cams)]
lists = [[[] for _ in range(num_cams)] for _ in range(num_cams)]
error = 0

for c1 in range(num_cams - 1):
for c2 in range(c1 + 1, num_cams):
if error == 0:
lists[c1][c2] = [Correspond() for _ in range(target_counts[c1])] # type: ignore
if lists[c1][c2] is None:
if not lists[c1][c2]:
error = 1
lists[c1][c2] = None
lists[c1][c2] = []

for edge in range(target_counts[c1]):
lists[c1][c2][edge].n = 0
lists[c1][c2][edge].p1 = 0
else:
lists[c1][c2] = None
lists[c1][c2] = []

if error == 0:
return lists

return False
return []


def four_camera_matching(
Expand Down Expand Up @@ -471,7 +471,7 @@ def take_best_candidates(


def py_correspondences(
img_pts: List[List[TargetArray]], # num_cams * num_targets[cam]
img_pts: List[List[Target]], # num_cams * num_targets[cam]
flat_coords: List[List[Coord2d]],
calib: List[Calibration],
vparam: VolumePar,
Expand Down
28 changes: 14 additions & 14 deletions openptv_python/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
from scipy import ndimage
from scipy.ndimage import map_coordinates, uniform_filter
from scipy.ndimage import uniform_filter

from .parameters import ControlPar

Expand Down Expand Up @@ -41,20 +41,20 @@ def fast_box_blur(filt_span: int, src: np.ndarray, cpar: ControlPar) -> np.ndarr
return row_accum


def split(img: np.ndarray, half_selector: int, cpar: ControlPar) -> np.ndarray:
"""Split image into two halves."""
cond_offs = cpar.imx if half_selector % 2 else 0
# def split(img: np.ndarray, half_selector: int, cpar: ControlPar) -> np.ndarray:
# """Split image into two halves."""
# cond_offs = cpar.imx if half_selector % 2 else 0

if half_selector == 0:
return
# if half_selector == 0:
# return

coords_x, coords_y = np.meshgrid(np.arange(cpar.imx), np.arange(cpar.imy // 2))
# coords_x, coords_y = np.meshgrid(np.arange(cpar.imx), np.arange(cpar.imy // 2))

coords_x = coords_x.flatten()
coords_y = coords_y.flatten() * 2 + cond_offs
# coords_x = coords_x.flatten()
# coords_y = coords_y.flatten() * 2 + cond_offs

new_img = map_coordinates(img, [coords_y, coords_x], mode="constant", cval=0)
return new_img
# new_img = map_coordinates(img, [coords_y, coords_x], mode="constant", cval=0)
# return new_img


def subtract_img(img1: np.ndarray, img2: np.ndarray, img_new: np.ndarray) -> None:
Expand Down Expand Up @@ -86,7 +86,7 @@ def prepare_image(
cpar: ControlPar,
dim_lp: int = 1,
filter_hp: int = 1,
filter_file: str | None = None,
filter_file: str = "",
):
"""Prepare an image for particle detection: an averaging (smoothing).
Expand All @@ -99,7 +99,7 @@ def prepare_image(
img = img.reshape((cpar.imy, cpar.imx)) # Reshape to 2D image
img_lp = ndimage.uniform_filter(
img,
size=(dim_lp * 2 + 1, dim_lp * 2 + 1),
size=dim_lp * 2 + 1,
mode="constant",
cval=0.0,
)
Expand All @@ -111,7 +111,7 @@ def prepare_image(
if filter_hp == 1:
img_hp = ndimage.uniform_filter(
img_hp.reshape((cpar.imy, cpar.imx)),
size=(3, 3),
size=3,
mode="constant",
cval=0.0,
).flatten()
Expand Down
17 changes: 14 additions & 3 deletions openptv_python/orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Optional, Tuple, Union

import numpy as np
import scipy

from openptv_python.constants import COORD_UNUSED

Expand Down Expand Up @@ -188,7 +189,7 @@ def orient(
cal: Calibration,
cpar: ControlPar,
nfix: int,
fix: List[np.ndarray],
fix: np.ndarray,
pix: List[Target],
flags: OrientPar,
sigmabeta: np.ndarray,
Expand Down Expand Up @@ -486,7 +487,13 @@ def orient(
)

# Interpret the results
# print(f"Coefficients (beta): {beta} Residuals: {residuals}")
print(
f"Coefficients (beta): {beta} \
Residuals: {residuals} \
singular_values: {singular_values} \
rank: {rank} \
"
)

# stopflag
stopflag = True
Expand Down Expand Up @@ -620,11 +627,15 @@ def raw_orient(
# matmul(beta, XPX, XPy, 6, 6, 1, 6, 6)

# Solve the linear system
beta, residuals, rank, singular_values = np.linalg.lstsq(X, y, rcond=None)
beta, residuals, rank, singular_values = scipy.linalg.lstsq(
X, y
) # , rcond=None)

# Interpret the results
print("Coefficients (beta):", beta)
print("Residuals:", residuals)
print("rank:", rank)
print("singular_values:", singular_values)

stopflag = True
for i in range(6):
Expand Down
Loading

0 comments on commit b4dbb0a

Please sign in to comment.