Sign in to follow this  
toe_head2001

Gaussian Blur (Clamped) v2.0 - (Jan 22, 2016)

Recommended Posts

Gaussian Blur (Clamped)

Effects -> Blurs -> Gaussian Blur (Clamped)

 

Description

This effect is exactly the same as the regular Gaussian Blur effect, except this effect gets clamped to the active selection. This stops colors (and transparency) from bleeding through from outside of the selection.

If you don't have anything selected, there is no need to run this effect (although, it wouldn't hurt anything if you did run it).

ui.png

 

Comparison

Gaussian Blur (Clamped) - Radius of 25:

selection.png -> clamped.png

Gaussian Blur - Radius of 25:

selection.png -> reg.png

 

Change Log

v2.0 (Jan 22, 2016)

  • Changed: Now works on non-rectangular selections. (Thanks MJW)

v1.0 (Jan 11, 2016)

  • Initial release

 

Download

:RightArrowBlue:  ClampedGaussianBlur.zip

 

Donate

PP_logo_h_100x26.png

 

Source Code

https://github.com/toehead2001/pdn-clamped-gaussian-blur

 

 

Icon based on icons from Fugue Icons.

  • Upvote 6

Share this post


Link to post
Share on other sites

A useful feature. More than once I've wished the non-selected area could be excluded from the blur. Oddly enough I was thinking about adding the same feature to a (non-Gaussian blur) plugin I'm working on.

Share this post


Link to post
Share on other sites

Thanks toe_head2001,

 

A step saver effect. Before I had to duplicate the blurred selection four or more times in order to bring back full opacity to the edges. 

Share this post


Link to post
Share on other sites

A useful feature. More than once I've wished the non-selected area could be excluded from the blur. Oddly enough I was thinking about adding the same feature to a (non-Gaussian blur) plugin I'm working on.

 

Oddly enough, this plugin is a side effect (no pun indented) of work I did for my Blur Fill plugin.

Edit: I see most (all?) the blur effects don't clamp to the selection. I never bothered to notice that before. Then again, I can't remember the last time I used a blur effect other than Gaussian Blur.

 

A step saver effect. Before I had to duplicate the blurred selection four or more times in order to bring back full opacity to the edges.

 

Before, I would copy the selection to a new image, since the canvas edge works as a clamp. Then I'd run Gaussian Blur.

Edited by toe_head2001

Share this post


Link to post
Share on other sites

Why do I always forget to test non-rectangular selections?  :/ Can a non-rectangle even be clamped?  I'll see if I can a solution.

Edited by toe_head2001

Share this post


Link to post
Share on other sites

Maybe not, but you could clamp to the bounding rectangle and clip to the entire selection.

 

That's what I'm doing already, unless I misunderstand you.

 

It creates a Rectangle based on the selection, and clamps the pixels outside the selection to the edges of the Rectangle edges. It then calls Gaussian Blur on the selection, and renders it to the dst surface.

Edited by toe_head2001

Share this post


Link to post
Share on other sites

Why do I always forget to test non-rectangular selections?  :/ Can a non-rectangle even be clamped?  I'll see if I can a solution.

toe_head2001,

This code should solve your problem:

 

Hidden Content:

Sorry if it doesn't work. I just wrote it off the top of my head and haven't tested it.

Magic is in OnSetRenderInfo.

  • Upvote 3

Share this post


Link to post
Share on other sites

This code should solve your problem...

 

Yes, it may, in part. When I said non-rectangular, I was specifically thinking of elliptical selections. The clamping would need to be radial.

 

Like so:

radial1.png---> radial2.png

 

 

 

Which of course can be done in code, but I have yet to try anything yet and measure the performance.

Edited by toe_head2001

Share this post


Link to post
Share on other sites

toe_head2001, I'm not sure how you produced the second image in your most-recent comment, but it it wasn't through a program, and you intend to write such a program, I may be able to help.

Share this post


Link to post
Share on other sites

toe_head2001, I'm not sure how you produced the second image in your most-recent comment, but it it wasn't through a program, and you intend to write such a program, I may be able to help.

 

Nothing fancy; Many layers and zooming.

 

Help is always welcome and appreciated.

Share this post


Link to post
Share on other sites

I said it was odd that I was thinking of adding the feature of looking at the only the selected region in a plugin I'm working on. What's odder is that the plugin does pretty much what you're interested in doing. It takes an "object" (a region surrounded by transparency) and extends it by setting each transparent pixel to the color of the nearest non-transparent pixel. It uses a separate surface, but the algorithm is O(n), where n in the number of pixels in the window. I describe the algorithm in my "Fast algorithm for finding the minimum distances to a set" comment.

 

(The idea of clamping the edge in this way would work for blurring convex selections, but wouldn't work for some non-convex selections, since the color from one edge could bleed over into another if the blur radius exceeded half the distance between the edges.)

 

Here is the flower image processed with the algorithm.

 

FlowersExtended_zps2xxyffmq.png

Edited by MJW
  • Upvote 1

Share this post


Link to post
Share on other sites

The code I wrote for you won't extrude a picture. It only blurs the selected pixels of an irregular selection without the influence of the non-selected pixels.

After looking at the code, the only problem will be calculating a proper alpha value for the blurred pixels. Perhaps it would use the source alpha or the most opaque alpha between the result pixel and the source pixel.

Share this post


Link to post
Share on other sites

BoltBait, thanks for the selection-copying code in your previous comments. That might be very useful for me.

Share this post


Link to post
Share on other sites

A plugin that would 'trail' objects towards a vanishing point would be very useful! ;)

I normally duplicate the object, make the background object smaller, use zoom blur, then change the opacity.
The plugin named Trail 3d doesn't do that and Pyro's trail is great but doesn't converge for perspective.

 

I guess that's slightly off topic, sorry Toe_Head.

Share this post


Link to post
Share on other sites

I said it was odd that I was thinking of adding the feature of looking at the only the selected region in a plugin I'm working on. What's odder is that the plugin does pretty much what you're interested in doing. It takes an "object" (a region surrounded by transparency) and extends it by setting each transparent pixel to the color of the nearest non-transparent pixel. It uses a separate surface, but the algorithm is O(n), where n in the number of pixels in the window. I describe the algorithm in my "Fast algorithm for finding the minimum distances to a set" comment.

 

(The idea of clamping the edge in this way would work for blurring convex selections, but wouldn't work for some non-convex selections, since the color from one edge could bleed over into another if the blur radius exceeded half the distance between the edges.)

 

Thank you. I'll take a close look at this during the weekend when I have plenty of time.

 

Concave selections are pretty rare (or maybe it's just me that never makes them), so I don't think that's a big deal.

 

 

... It only blurs the selected pixels of an irregular selection without the influence of the non-selected pixels...

 

Just because the non-selected pixels are transparent, doesn't mean they aren't influencing the selected ones. That's why transparency is bleeding into the blur when your code is run. This is why the clamping is so important.

 

The code you posted in regards to the PdnRegion will be helpful though. Much appreciated.

I'd seen PdnRegion in other people's code before, but I never bothered to see what it did or what it was used for.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this