Compositor new node: Kuwahara filter

You can download the current version here: Blender Builds - blender.org
Updates:

  • Changed parameter naming and defaults
  • Make it clear viewport compositor is not supported
  • Built packages for windows, macos and linux
  • Made color part of filters, so its color is now purple

Since the kernel size is an absolute value in pixels, its effect is highly dependent on the size of the input image. For 1k-4k images the value 1 almost has no effect. That’s why I chose 4.
Another reason is the anisotropic variation will only be free of visible artefacts for values >= 4 (ideally should be >=8 actually). I also adjusted the default for smoothing accordingly, where the effect starts to get noticeable starting from the value 2.

I don’t think strength reflects the effect well. Kernel size (now called “size”) is the value actually affecting strength. Sigma (now called “smoothing”) only influences edges but not how “stylized” the image looks. So I went with the user-centric name “smoothing” : )

2 Likes

Still no dice for me with this new build. Is there anything needed besides activating the full frame compositor in the experimental settings ?

You will also need to set it to the active compositor:
Go to Compositor → Options and set Execution Mode to Full Frame:

Sorry for the confusion, I updated the description of the first post.

Classic mode works fine but Anisotropic gives me this result.

Input

Anisotropic size 4 smoothing 2

The image sequence is PNG 1920*1080, and I’m not sure if there is a way to log the execution time, but it updates on frame change in about 0.6 or 0.7s on this machine (gtx970).

Can you try with a filter size >= 8 ? Also, your test image is already smooth and stylized, so the effect probably won’t be obvious…

The glitch is gone at 8 :

Anisotropic size 8 smoothing 2

but it takes 18s to render

1 Like

Ok, thanks for testing!
I have performance optimzation on my todo list, might have to do it sooner though

I see artifacts all around the image borders as well, perhaps that could be improved.

Here is the current build: Blender Builds - blender.org

Changes:

  • Solved issue with black pixel artefacts. Please let me know if this solves the issue for your images as well.
  • Solved the issue with artefacts at image border
  • Implemented filter for tiled compositor. Note: this is much slower than full-frame compositor. For testing please use full-frame compositor.
  • Changed meaning of “size” parameter. You should see significant changes but without any artefacts starting from size = 1
3 Likes

Latest update:

  • Kuwahara filter is now in main :slight_smile:
  • Classic variation is now about 3.5x faster
  • Anisotropic variation is now 4x faster. However, results are less accurate, and this is what this post is about.

The patch #108796 speeds up the anisotropic variation significantly, but results are less accurate. We would like to ask for artist feedback regarding the significance of the difference.

Following images show how the new patch affects results (left: original, middle: fast and inaccurate, right: slow and accurate):



Full render side by side (left: fast and inaccurate, right: slow and accurate):

You can try it out the latest version with the speedup yourself here:

11 Likes

I tried it with a bit of tricky situation. Maybe a bit of an extreme case that would not use Kuwahara filter.

Used default values (size: 4, smoothing: 2).

Original:

Objects have more obvious color differences. Iron bars and shadow of them are crossed, making a grid-like pattern.

Fast:

Accurate:

Fast one shows more artifacts along the edges. Even the most obvious edge (where cage’s red base and and the floor meets) are blurred.

Render with Classic mode for comparison:

I imagine the fast one could be trickier to use for animation rendering in some situations, due to more instability between frames.

That said, I definitely see generally 4x faster speed as you said.

1 Like

Hello! First of all, let me congratulate you on getting this into main, thanks for your awesome work and for adding this long awaited node !

Here’s my two cents on the speed vs accuracy, coming from a studio perspective that specializes in stylization in Blender:

It’s true that the “accurate” version can run prohibitively long sometimes, in a sense where it almost hinders the artistic process of iterating over the settings to adjust the node tree (it’s also a limitation of the compositor which has no caching, meaning any variation in a node tree containing the Kuwahara filter basically grinds to a halt at every variable change.) That being said, the results are very promising and great in most cases, and stable enough for animation.

The fast version enables faster tweaking which is great for the compositors, but as @sunkper demonstrated, the artifacts generated (and flicker heightened during animation) in some cases unfortunately simply render the shots unnacceptable from a quality standpoint, making the filter unusable in some demanding production settings.

Ideally, I would say the best option is to have a “preview” toggle such as with the defocus node, which switches between the fast and accurate algorithms:

However, I understand that this might not be the most optimal option for you as you’d have to maintain and update both implementations.

If I really had to pick one, I would choose the accurate version, even if it means much slower performance (and keep my fingers crossed for performance updates, and more importantly, the GPU implementation, as it could resolve all performance issues!)

2 Likes

Thanks for adding this filter. Kuwahara Anistoropic mode seems to be insanely slow with 4k or highres images.

The classic mode is like 1 sec, the anistoropic mode is more like 30+ sec with a 4kx3k 16bit image.

1 Like

Does anisotropic mode use polynomial optimization?

Not at the moment, but the new implementation that we shall merge soon uses it.

3 Likes

This is still WIP but i wanted to say thanks to anyone who worked on this filter, i used the anisotropic version

Original render looks like this and i removed the sphere for the Kuwahara filter version

9 Likes

I have a question. Do we have legacy Kuwahara filter with box capturing, or enhanced modern variand by Gueseppe Papari with disk/round capturing and sectors?
This is proper paper, i believe:
https://www.researchgate.net/figure/Effect-of-the-indetermination-of-the-Kuwahara-filter-for-a-2-D-signal-a-Input-image_fig8_221226072

And here an idea to replace Gaussian function to polynomial

Anisotropic Kuwahara: https://www.umsl.edu/~kangh/Papers/kang-tpcg2010.pdf

Both are implemented, anisotropic is the enhanced version you’re referring to.

1 Like

Oh my!
Anisotropic looks so nice in the video above!

Thanks, i will test it with pleasure. I hope, it will take it`s place in the new openmovie!