Skip to content

Commit

Permalink
Added support for cupy convolution if installed
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoitink committed Mar 18, 2024
1 parent 8502d79 commit a863b84
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/simulatedmicroscopy/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import h5py
import numpy as np
import scipy.signal
import skimage.measure

from .input import Coordinates
Expand Down Expand Up @@ -398,9 +397,21 @@ def convolve(self, other: type[Image]) -> type[Image]:
"Cannot convolve images with different pixel sizes"
)

self.image = scipy.signal.convolve(
self.image, other.image, mode="same"
)
try:
import cupy as cp
from cupyx.scipy import signal as cusignal

self.image = cusignal.fftconvolve(
cp.asarray(self.image), cp.asarray(other.image), mode="same"
).get()
except ImportError:
# resort to scipy if cupy is not available

import scipy.signal

self.image = scipy.signal.convolve(
self.image, other.image, mode="same"
)

self.is_convolved = True
self.metadata["is_convolved"] = True
Expand Down

0 comments on commit a863b84

Please sign in to comment.