# Blur filter using Parallel Accelerator

**URL:** <https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492>\
**Category:** General Usage\
**Tags:** images, parallel\
**Created:** [May 3, 2017, 9:02am UTC](https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492 "2017-05-03T09:02:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naelson\_douglas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naelson_douglas/32/1790_2.png) [@Naelson\_douglas](https://discourse.julialang.org/u/Naelson_douglas)\
**Post date:** [May 3, 2017, 9:02am UTC](https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492/1 "2017-05-03T09:02:58Z")

</div>

Hello.

I’m trying to process an image by using [Paralle Accelerator](http://parallelacceleratorjl.readthedocs.io/) in the following way (it’s the documentation example,actually)

runStencil(buffer\_B, Band\_B, 1, oob\_src\_zero) do b, a  
b[0,0] = blur(a)  
return a, b  
end

And this code runs in nearly 20 seconds on my machine with an 150MB input image.

But by using the blur filter from the package Images ([imblur](https://github.com/JuliaImages/Images.jl) is the function name), I get the same result in something like 7 seconds.

Shouldnt the parallel blur be faster than the sequential function or am I doing it wrong?

---

<div class="post-metadata">

**Author:** ![kevin.squire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin.squire/32/62_2.png) [@kevin.squire](https://discourse.julialang.org/u/kevin.squire)\
**Post date:** [May 3, 2017, 1:55pm UTC](https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492/2 "2017-05-03T13:55:28Z")

</div>

I haven’t looked at that code, but I believe Tim Holy spent a lot of effort optimizing the memory access for many algorithms in Images so that they avoid cache misses (mimicking techniques used in, e.g., halide). For operations on large images, this is potentially more important than parallelization (although the algorithms in Images might also us parallelization as well–not sure).

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [May 5, 2017, 7:41am UTC](https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492/3 "2017-05-05T07:41:02Z")

</div>

Heck, I’m surprised it even takes 7 seconds. If you’re blurring, make sure you take advantage of the possibility of separability:

```julia
julia> img = rand(4000,4000);

julia> kf = KernelFactors.gaussian((1.5,1.5)); # represented as a separable filter

julia> @time imfilter(img, kf);
  0.370443 seconds (18.36 k allocations: 245.275 MB, 22.67% gc time)

julia> k = Kernel.gaussian((1.5,1.5)); # not represented as a separable filter

julia> @time imfilter(img, k);
  1.132960 seconds (18.40 k allocations: 245.284 MB, 11.39% gc time)

```

(all times measured after suitable warmup).

ImageFiltering also supports parallel computation, currently implemented only for separable filters. See [http://juliaimages.github.io/latest/imagefiltering.html#Multithreading-1](http://juliaimages.github.io/latest/imagefiltering.html#Multithreading-1).

---

<div class="post-metadata">

**Author:** ![Naelson\_douglas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naelson_douglas/32/1790_2.png) [@Naelson\_douglas](https://discourse.julialang.org/u/Naelson_douglas)\
**Post date:** [September 4, 2017, 2:08pm UTC](https://discourse.julialang.org/t/blur-filter-using-parallel-accelerator/3492/4 "2017-09-04T14:08:43Z")

</div>

Hey. Thanks for the help (and sorry for the looooong time to answer)  
It really explains a lot.
