Clip / mask filter by using a shape

How can I clip a filter like “blur” to a shape? There are tutorials that show how to make a shape disappear behind another shape. But I’m looking for something different:

I have a background image and above (z-axis) I have a smaller transparent rectangle. Now I want to apply a filter like “blur” but only inside the rectangle.

Actually my final goal is to apply the filter to the outside of the rectangle, but I’m already stuck with applying it to the inside:

Is this possible?

I found 2 solutions:

Solution 1 is to copy the image, put the copy in a group together with the rectangle and blur and then blend the image-copy “straight onto” the rectangle. Check the “invert” option of the rectangle.
Disadvantage: When I move the image in the animation, I also have to move the copy.

Solution 2: Put a blur layer and a warp layer into a filter group. Set warp source coordinates to form a rectangle where the blur should occur. Set the warp target coordinates equal to its source coordinates. (Actually the warp is just needed to get a clipped copy of the image).
Disadvantage: This doesn’t solve the actual goal to make the outside blurry. Setting the coordinates is cumbersome.

Is there an easier solution?

The filter group is your friend, yes. You need to put blur layer inside it along with the mask (rect. layer in my case with ‘Alpha over’ blend method) and set filter group’s ‘Blend method’ to ‘Composite’.
Here’s a quick example: MaskBlur.sif (32.2 KB)

As you can see everything is blurred except for the part of the mountain, sun and one star above.

4 Likes

Great, exactly what I was looking for, thank you very much. I still don’t get how that works, however. What confuses me even more is that the layer Z depth order of “blur” and “rectangle” doesn’t matter.

Think of the filter group as a fake - it doesn’t group anything. What it does is it takes a snapshot of everything that below it and then applies effects on top of that composition that you put into filter group. It basically acts like a copy. So you have your original composition (non blurred) and your blurred copy with the mask on top of it.

‘Z depth’ of the mask and blur doesn’t matter because in this case it produces the same result. Think about it, what result will you get if you apply mask first and then blur? What if those operations are reversed? The same result in both cases.

Thank you very much for the explanation. If it’s a copy, that makes sense and now I understand why the order doesn’t matter.

I was absolutely sure that I also tried the warp layer and stretch layer outside a filter group and got a copy. This falsely made me think that distortion layers are responsible for the copy (e.g. in the reflection / shadow tutorial on YT). But it appears that I remember it wrong.