From cd68f55bef4a47dd14823d693d9542033b827bbd Mon Sep 17 00:00:00 2001 From: Kevin John <58094058+kevin-cgc@users.noreply.github.com> Date: Thu, 6 Feb 2025 21:06:39 -0700 Subject: [PATCH 1/2] fix: incorrect phase delta wrapping --- motion_magnification_pytorch.ipynb | 5 ++--- phase_based_processing.py | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/motion_magnification_pytorch.ipynb b/motion_magnification_pytorch.ipynb index 88ee77b..3262820 100644 --- a/motion_magnification_pytorch.ipynb +++ b/motion_magnification_pytorch.ipynb @@ -631,7 +631,7 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -660,8 +660,7 @@ " _delta = torch.angle(curr_pyr) - ref_phase \n", "\n", " # get phase delta wrapped to [-pi, pi]\n", - " phase_deltas[:, vid_idx, :, :] = ((torch.pi + _delta) \\\n", - " % 2*torch.pi) - torch.pi\n", + " phase_deltas[:, vid_idx, :, :] = ((torch.pi + _delta) % (2*torch.pi)) - torch.pi\n", " \n", " ## Temporally Filter the phase deltas\n", " # Filter in Frequency Domain and convert back to phase space\n", diff --git a/phase_based_processing.py b/phase_based_processing.py index ed984b6..1a8a66c 100644 --- a/phase_based_processing.py +++ b/phase_based_processing.py @@ -119,8 +119,7 @@ def process_single_channel(self, _delta = torch.angle(curr_pyr) - ref_phase # get phase delta wrapped to [-pi, pi] - phase_deltas[:, vid_idx, :, :] = ((torch.pi + _delta) \ - % 2*torch.pi) - torch.pi + phase_deltas[:, vid_idx, :, :] = ((torch.pi + _delta) % (2*torch.pi)) - torch.pi ## Temporally Filter the phase deltas # Filter in Frequency Domain and convert back to phase space From 3819edc074a456f021394916a5765cd5659032a2 Mon Sep 17 00:00:00 2001 From: Kevin John <58094058+kevin-cgc@users.noreply.github.com> Date: Mon, 3 Mar 2025 12:27:44 -0700 Subject: [PATCH 2/2] fix: specify dimmensions for fftshift This avoids the reconstruction being offset by num_frames/2 --- motion_magnification_pytorch.ipynb | 4 ++-- phase_utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/motion_magnification_pytorch.ipynb b/motion_magnification_pytorch.ipynb index 3262820..7bf60d5 100644 --- a/motion_magnification_pytorch.ipynb +++ b/motion_magnification_pytorch.ipynb @@ -569,13 +569,13 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## Get DFT of all video frames\n", "frames_tensor = torch.tensor(np.array(frames)).type(torch.float32).to(device)\n", - "video_dft = torch.fft.fftshift(torch.fft.fft2(frames_tensor, dim=(1,2))).type(torch.complex64).to(device)" + "video_dft = torch.fft.fftshift(torch.fft.fft2(frames_tensor, dim=(1,2)), dim=(1,2)).type(torch.complex64).to(device)" ] }, { diff --git a/phase_utils.py b/phase_utils.py index 3134cb5..12d87cc 100644 --- a/phase_utils.py +++ b/phase_utils.py @@ -147,7 +147,7 @@ def create_gif_from_numpy(save_path, images): ## Misc utils def get_fft2_batch(tensor_in): - return torch.fft.fftshift(torch.fft.fft2(tensor_in, dim=(1,2))).type(torch.complex64) + return torch.fft.fftshift(torch.fft.fft2(tensor_in, dim=(1, 2)), dim=(1, 2)).type(torch.complex64) def bandpass_filter(freq_lo, freq_hi, fs, num_taps, device):