# Adapt window level and width after using vtkImageConvolve

**URL:** <https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397>\
**Category:** Development\
**Created:** [October 2, 2023, 2:26am UTC](https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397 "2023-10-02T02:26:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eightysix](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@eightysix](https://discourse.vtk.org/u/eightysix)\
**Post date:** [October 2, 2023, 2:26am UTC](https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397/1 "2023-10-02T02:26:38Z")

</div>

I’ve been able to apply a sharpening filter using `vtkImageConvolve`, but it seems this operation also alters the windowing scale. I have to use a different WW/WL to achieve the same appearance I have with non-sharpened image data.  
Is there a way to normalize the image windowing scale after applying the convolution filter?

---

<div class="post-metadata">

**Author:** ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)\
**Post date:** [October 2, 2023, 11:06am UTC](https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397/2 "2023-10-02T11:06:21Z")

</div>

The first thing to verify is that your convolution kernel is normalized. If it is, then the only changes in WW/WL will be due to small amounts of overshoot due to the sharpening.

---

<div class="post-metadata">

**Author:** ![eightysix](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/e/ecccb3/32.png) [@eightysix](https://discourse.vtk.org/u/eightysix)\
**Post date:** [October 2, 2023, 12:05pm UTC](https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397/3 "2023-10-02T12:05:14Z")

</div>

Thank you for the reply. I used the “Sharpen 3x3” kernel from Horos:

```auto
vtkNew<vtkImageConvolve> convolveFilter;
        convolveFilter->SetInputData([wrapper getImageData]);
double kernel[9] = {-1, 0, -1, 0, 7, 0, -1, 0, -1};
convolveFilter->SetKernel3x3(kernel);
convolveFilter->Update();

```

I resolved the issue with WW/WL by multiplying both by 3 when using the sharpening filter; this way I get the same window appearance I have in non-sharpened images. I don’t know if there’s something wrong in my code or if this is an expected behavior.

By the way, what is the expected RAM usage of this operation? I’m applying it on a ~1GB DICOM series and the memory usage increases to ~1.9GB after performing the sharpening. Is this correct?

---

<div class="post-metadata">

**Author:** ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)\
**Post date:** [October 2, 2023, 1:11pm UTC](https://discourse.vtk.org/t/adapt-window-level-and-width-after-using-vtkimageconvolve/12397/4 "2023-10-02T13:11:02Z")

</div>

Normalize the kernel instead of changing the WW/WL. The normalization is easy to do. Just sum all the elements of the kernel, and then divide the elements by this sum:

```
-1 * 4 + 7 = 3

```

The kernel after normalization is as follows:

```
-0.3333333333333333, 0.0, -0.3333333333333333,
 0.0, 2.3333333333333333, 0.0,
-0.3333333333333333, 0.0, -0.3333333333333333

```

It’s natural for the memory usage to increase, since you will have both the old image and the new image in memory.
