# How to speed up for 3D filtering

**URL:** https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719
**Category:** Beginner Questions
**Created:** [December 21, 2020, 5:48am UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719 "2020-12-21T05:48:47Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![buyierfei](https://discourse.itk.org/user_avatar/discourse.itk.org/buyierfei/32/2309_2.png) [@buyierfei](https://discourse.itk.org/u/buyierfei)
#### Post date: [December 21, 2020, 5:48am UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/1 "2020-12-21T05:48:47Z")

</div>

I found it such slow that using built-in 3D filtering method directly. For example, I want to implement mean filtering in a 3D image data, which size is 1024 \* 1024 \* 1024, and I use itkMeanImageFilter method, but it seams too slow, how can I do for speed it up?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 21, 2020, 3:09pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/2 "2020-12-21T15:09:35Z")

</div>

How big is your kernel? Mean filter should be relatively fast for smaller kernels (3x3x3, aka radius 1). Median filter is much slower. Number one thing to check: are you running in release mode? Debug is 1-2 orders of magnitude slower.

---

<div class="post-metadata">

### Author: ![buyierfei](https://discourse.itk.org/user_avatar/discourse.itk.org/buyierfei/32/2309_2.png) [@buyierfei](https://discourse.itk.org/u/buyierfei)
#### Post date: [December 21, 2020, 3:20pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/3 "2020-12-21T15:20:20Z")

</div>

thanks. kernal size is 3_3_3, and is in release mode. I found that the CPU usage in the task manager is about 10%. How can we put more computing resources into this process?

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [December 21, 2020, 3:36pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/4 "2020-12-21T15:36:48Z")

</div>

If you’re only getting 10% CPU utilization, then the process is probably thrashing. How much memory do you have?

---

<div class="post-metadata">

### Author: ![buyierfei](https://discourse.itk.org/user_avatar/discourse.itk.org/buyierfei/32/2309_2.png) [@buyierfei](https://discourse.itk.org/u/buyierfei)
#### Post date: [December 21, 2020, 3:44pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/5 "2020-12-21T15:44:36Z")

</div>

CPU is AMD ryzen 2600, and memory is 16g

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 21, 2020, 4:06pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/6 "2020-12-21T16:06:29Z")

</div>

Does 1024x1024x100 image gets processed 10x faster? If the speedup is greater, your original image processing speed is limited by available memory.

What happens if you limit number of threads to say 4? You can use `filter->SetNumberOfThreads(4);`

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [December 21, 2020, 4:08pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/7 "2020-12-21T16:08:11Z")

</div>

What is your pixel type? Doubles would probably cause memory problems, but anything smaller ought to fit in 16 gig. I’d guess the filter needs two copies of the image in memory, the input and output images.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [December 21, 2020, 4:17pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/8 "2020-12-21T16:17:32Z")

</div>

> [@buyierfei](#):
>
> kernal size is 3_3_3,

The `MeanImageFilter` does not have a “kernel size” parameter. It has a `Radius` parameter, which if set to 3 would mean the “size” of the kernel is [7,7,7] which is 343 pixel. That is some what of a large 3d convolution.

I think there is a more efficient implementaion in the [`BoxMeanImageFilter`](https://itk.org/Doxygen/html/classitk_1_1BoxMeanImageFilter.html).

---

<div class="post-metadata">

### Author: ![buyierfei](https://discourse.itk.org/user_avatar/discourse.itk.org/buyierfei/32/2309_2.png) [@buyierfei](https://discourse.itk.org/u/buyierfei)
#### Post date: [December 21, 2020, 4:17pm UTC](https://discourse.itk.org/t/how-to-speed-up-for-3d-filtering/3719/9 "2020-12-21T16:17:59Z")

</div>

pixel type is char，and memory has been used 9/16g
