Sign in to follow this  
ArgusMagnus

Edge Detection

Recommended Posts

Effect->Stylize->Edge Detection (Argus)

 

Download: https://onedrive.live.com/redir?resid=429F16CCEF18E484!339757&authkey=!AJ0aYSIXTh_4Jhs&ithint=folder%2ctxt

(Copy the files ArgusPaintNet.EdgeDetection.dll and ArgusPaintNet.Shared.dll to the paint.net/Effects folder)

 

This effect uses an edge detection algorithm. It draws edges with given colors and sets the other pixels to transparent.

 

I haven't had any good idea for the name, so I called it Edge Detection for now, the (Argus) is simply to make it better distinguishable from the built in Edge Detect effect. If anyone has an idea for a better name, feel free to share it :-)

 

UI Explanation (See example below):

Lower Threshold: All pixels with values (Structur Tensor Eigenvalues) below this threshold are fully transparent: Higher Threshold --> Less Edges detected

Upper Threshold: All pixels with values above this threshold are fully opaque. The range of "good" values really depends on the image. For hard edges (extreme case: black line on white), "good" values may go up to 1, for softer edges (as typically found in photographes), "good" values will usually be below 0.2

Color/Color2/Angle/Hue Direction: ​Edges with a normal angle the same as the chosen Angle are drawn in the color set in Color, edges with a normal angle perpendicular to Angle are drawn in the color set in Color2, ​in between the color is interpolated between Color and Color2. Hue Direction determines how the Hue value is interpolated.

Difference Filter: The Kernel used to get the image derivates in x and y direction. I have yet to encounter a situation where I needed to change this value. If you change this value, a lot of calculations have to be redone. Some time may pass before you see something happening.

Smoothing Radius: As expected, smoothes the output.

 

Performance:

Calculating initial values (Structur Tensors) may take some time, therefore, depending on the selection size, it may take some time after the effect dialog pops up before you can see something happening. If you change the value "Difference Filter" these calculations have to be redone.

Smoothing is also somewhat expensive, which you can see if you change the smoothing radius.

Intermediate values (Structur Tensors, eigenvalues of smoothed Tensors) are held in memory so re-rendering the output for different Threshold/Color/Angle values is fast. The cost for that is memory usage: Roughly 24 bytes per Pixel are used (excluding the memory used for the source and destination surface).

 

EdgeDetectionBuilding_zpshxclspuu.png

 

EdgeDetectionFowers_zps9uvmmzzh.png

Edited by ArgusMagnus
  • Upvote 8

Share this post


Link to post
Share on other sites

Thanks ArgusMagnus.

 

Interesting effect. I copied the original on four layers and used different settings for each one to obtain this.

 

house-dallas-4cd89db.png

  • Upvote 2

Share this post


Link to post
Share on other sites

Interesting effect Argus - thanks for sharing! B)
Clever way of linking the two threshold sliders and limiting the angle chooser.

Unfortunately I managed to crash it! (or rather it crashed Pdn). Threading error below.
I had successfully used the effect. I then used 'undo' (to duplicate my original 1281 by 907 image). Then used 'Effects/repeat Edge detection (Argus)' which caused the crash.


File: C:\Program Files\paint.net\Effects\ArgusPaintNet.EdgeDetection.dll
      Name: ArgusPaintNet.EdgeDetection.EdgeDetectionEffect
      Version: 1.0.5744.32049
      Author: Argus Magnus
      Copyright: Copyright © ArgusMagnus 2015
      Website: http://www.getpaint.net/redirect/plugins.html
      Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ArgusPaintNet.EdgeDetection.EdgeDetectionEffect.OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
   at PaintDotNet.Effects.Effect`1.OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs) in d:\src\pdn\paintdotnet\src\Effects\Effect`1.cs:line 67
   at PaintDotNet.Effects.BackgroundEffectRenderer.ThreadFunction() in d:\src\pdn\paintdotnet\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 218
   --- End of inner exception stack trace ---
   at PaintDotNet.Effects.BackgroundEffectRenderer.DrainExceptions() in d:\src\pdn\paintdotnet\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 431
   at PaintDotNet.Menus.EffectMenuBase.DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion, PdnRegion regionToRender, IRenderer`1 clipMaskRenderer, Surface originalSurface, Exception& exception) in d:\src\pdn\paintdotnet\src\PaintDotNet\Menus\EffectMenuBase.cs:line 1527

  • Upvote 1

Share this post


Link to post
Share on other sites

I had the same problem when I used the "REPEAT" option. I thought it was my computer since it is a kind of old.

Share this post


Link to post
Share on other sites

Thanks for the feedback red ochre.

I've uploaded a fix, should work now.

 

(The problem was, that the initialization method was not called, when the effect was run without UI via repeat)

Share this post


Link to post
Share on other sites

Great effect, much better than the one built-in to PDN. You really should zip your files instead of leaving open xxx.dll's on a server somewhere, it's a bit unsettling to download them like that....

 

oRe9jVT.gif

 

Here is another cool one. It looks almost frozen.....

 

7iNcHSo.gif

Edited by racerx
  • Upvote 2

Share this post


Link to post
Share on other sites

Small Update: I changed the range of the threshold values and improved cancelling behaviour.

 

I'm not sure this is the optimum yet. The problem is, that the range which makes sense really depends on the image. For an image with hard edges (black on white), one would want a large range, possibly with a maximum even above 1. For images with softer edges (photographes, realistic drawings, etc.) chosen values will likely be below 0.2 or even 0.1. Of course these values can be chosen even if the range is [0,1] but its less confortable if you have a slider going from 0 to 1 but you are only interested in values between 0 and 0.1.

 

So if you think, I should allow another range for the sliders, tell me :)

 

 

@racerx: The assemblies are not zipped up, because... well... essentially because it's easier for me (I would need to have multiple zip files of which most would contain the ArgusPaintNet.Shared.dll file, so I would need to update every zip if I updated the shared dll and wanted all zips to contain the newest version). But if you select multiple files or download the whole folder, OneDrive will zip it up for you ;)

Edited by ArgusMagnus

Share this post


Link to post
Share on other sites

ArgusMagnus! Thank you very much for the plugin and your effort. mxfburwu.gif

 

Sorry! 2umngu7w.png Tomorrow's day. :)

 

9l3jjshh.png

 

kws4d9n3.png

 

9jdca2ut.png

Edited by Seerose
  • Upvote 2

Share this post


Link to post
Share on other sites

Would "Edge Detect+" be a better name? According to the plugin index it is not taken yet.

 

Does anyone use the "Corner" mode? (This plugin originally started out as a corner detection plugin, but as I kept going and tested the plugin, I began to see, that edge detection yields much more interesting results than corner detection and the math is almost identical, so switching between the two modes requires very little code changes). If not, I might remove the option altogether and instead add an option to perform the algorithm and different versions of the image. Currently the algorithm is performed on a grayscale image, but it could just as easily be run on individual channels

Share this post


Link to post
Share on other sites

I tried the Corner Mode, but didn't like the results. Replacing it with something better sounds like a good idea to me.

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