# Periodic convolution, equivalent to convolution2d from scipy

**URL:** https://discourse.julialang.org/t/periodic-convolution-equivalent-to-convolution2d-from-scipy/110191
**Category:** General Usage
**Tags:** dsp, image-processing
**Created:** [February 14, 2024, 1:28am UTC](https://discourse.julialang.org/t/periodic-convolution-equivalent-to-convolution2d-from-scipy/110191 "2024-02-14T01:28:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![modifiedbear](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/modifiedbear/32/50494_2.png) [@modifiedbear](https://discourse.julialang.org/u/modifiedbear)
#### Post date: [February 14, 2024, 1:28am UTC](https://discourse.julialang.org/t/periodic-convolution-equivalent-to-convolution2d-from-scipy/110191/1 "2024-02-14T01:28:47Z")

</div>

Hi! I am new to convolutions. I am looking to implement a convolution with wrapped/toroidal boundaries (i.e. for CircularArrays).

```julia
# matrix = N x M matrix
# smaller_matrix = some sort of kernel
convolve2d(matrix, smaller_matrix, mode='same', boundary='wrap')

```

In other words, a smoothing filter that acts periodically. I know

```julia
DSP.conv(vector, vector, matrix)

```

achieves something similar, but I don’t know how to implement wrapped boundaries.

Thanks!

---

<div class="post-metadata">

### Author: ![trahflow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trahflow/32/30585_2.png) [@trahflow](https://discourse.julialang.org/u/trahflow)
#### Post date: [March 6, 2024, 12:30pm UTC](https://discourse.julialang.org/t/periodic-convolution-equivalent-to-convolution2d-from-scipy/110191/2 "2024-03-06T12:30:29Z")

</div>

Hi,  
I know the reply comes a bit late, but have a look at [ImageFiltering.jl](https://juliaimages.org/ImageFiltering.jl/dev/). In particular the function `imfilter(matrix, kernel; border="circular")` supports a keyword argument `border` that can be set to (amongst other things) “circular” to achieve what you want.  
Despite having the word “Image” in its name, the package works for general nd-arrays.

---

<div class="post-metadata">

### Author: ![modifiedbear](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/modifiedbear/32/50494_2.png) [@modifiedbear](https://discourse.julialang.org/u/modifiedbear)
#### Post date: [March 6, 2024, 11:43pm UTC](https://discourse.julialang.org/t/periodic-convolution-equivalent-to-convolution2d-from-scipy/110191/3 "2024-03-06T23:43:16Z")

</div>

thanks a bunch
