Skip to content

Commit

Permalink
fix power spectrum widget (log, properly use axes)
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Sep 25, 2023
1 parent c364e92 commit b85c86f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/blik/widgets/power_spectrum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import TYPE_CHECKING

import dask.array as da
import numpy as np
from magicgui import magic_factory
from scipy.fft import fftn, fftshift

Expand All @@ -15,11 +16,18 @@
def power_spectrum(
image: "napari.layers.Image",
) -> "napari.types.LayerDataTuple":
"""
Power spectrum (log scale) of the image.
First centers in real space on the origin to remove shift effects.
"""
axes = (1, 2) if image.metadata["stack"] else None
raw = da.compute(image.data)[0]
power_spectrum = abs(fftshift(fftn(raw, axes=axes)))
power_spectrum = np.abs(
fftshift(fftn(fftshift(raw, axes=axes), axes=axes), axes=axes)
)
return (
power_spectrum,
np.log(power_spectrum + 1),
{"name": f"{image.name} - power spectrum", "scale": image.scale},
"image",
)

0 comments on commit b85c86f

Please sign in to comment.