Skip to content

Commit

Permalink
use fftspectrum-rs and drop opencv (#16)
Browse files Browse the repository at this point in the history
* update freq_dft_view to use fftspectrum-rs

* remove opencv from requirements.txt

* fix typo

* Delete dft-view/requirements.txt

---------

Co-authored-by: emotion3459 <176516814+emotion3459@users.noreply.github.com>
  • Loading branch information
NSQY and emotion3459 authored Dec 22, 2024
1 parent 93e5f63 commit 64250e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
26 changes: 12 additions & 14 deletions dft-view/freq_dft_view.ppy
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,25 @@ __all__ = [

class DFTViewPlugin(MappedNodesViewPlugin):
_config = PluginConfig('dev.setsugen.fft_view', 'DFT View')
_url = 'https://github.com/sgt0/vapoursynth-fftspectrum-rs'

def get_node(self, node: vs.VideoNode) -> vs.VideoNode:
import numpy as np
from cv2 import DFT_COMPLEX_OUTPUT, dft # type: ignore

if not hasattr(vs.core, 'fftspectrum_rs'):
raise AttributeError(
'The required plugin "fftspectrum_rs" is not installed. '
f'Please install it from: {self._url}'
)

planes = split(depth(node, 32))

def _to_polar(f: vs.VideoFrame, n: int) -> vs.VideoFrame:
src = np.asarray(f[0])
dft_shift = np.fft.fftshift(dft(src, flags=DFT_COMPLEX_OUTPUT))
mag = np.sqrt(np.power(dft_shift[:, :, 1], 2), np.power(dft_shift[:, :, 0], 2))
dst = f.copy()
np.copyto(np.asarray(dst[0]), np.log(mag) / 10)
return dst

if len(planes) == 1:
y = planes[0]

return y.std.ModifyFrame(y, _to_polar)
return planes[0].fftspectrum_rs.FFTSpectrum()

planes = [c.std.ModifyFrame(c, _to_polar).text.Text(text=k) for k, c in zip(node.format.name, planes)]
planes = [
c.fftspectrum_rs.FFTSpectrum().text.Text(text=k)
for k, c in zip(node.format.name, planes)
]

subsampling = node.format.subsampling_w, node.format.subsampling_h

Expand Down
1 change: 0 additions & 1 deletion dft-view/requirements.txt

This file was deleted.

0 comments on commit 64250e8

Please sign in to comment.