Sign in to follow this  
Followers 0
BoltBait

Remove Dust from Scanned Photos

15 posts in this topic

So, I was scanning a ton of photographs today and kept having to do the same steps to remove dust from the images.

I automated it into a plugin.

Enjoy.

RemoveDustUI.png

 

 

// Name: Remove Dust
// Submenu: Photo
// Title: BoltBait's Remove Dust v4.0
// Author: BoltBait
// URL: http://BoltBait.com/pdn
// Desc: Remove dust from scanned photographs
// KeyWords: dust|stamp|scan|clone
#region UICode
byte Amount1 = 0; // [1] Dust Color|White|Black
#endregion

// Setup for using Lighten blend op
private BinaryPixelOp lightenOp = LayerBlendModeUtil.CreateCompositionOp(LayerBlendMode.Lighten);
// Setup for using Darken blend op
private BinaryPixelOp darkenOp = LayerBlendModeUtil.CreateCompositionOp(LayerBlendMode.Darken);

// Here is the main render loop function
unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        ColorBgra* prevPtr = src.GetPointAddressUnchecked(rect.Left, y);
        ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y);
        ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra CurrentPixel;

            if (Amount1 == 0)
            {
                // Remove white dust
                CurrentPixel = darkenOp.Apply(*prevPtr, *srcPtr);
            }
            else
            {
                // Remove black dust
                CurrentPixel = lightenOp.Apply(*prevPtr, *srcPtr);
            }

            *dstPtr = CurrentPixel;
            
            prevPtr = srcPtr;
            srcPtr++;
            dstPtr++;
        }
    }
}
There is no UI. Just run it and the white dust specks are gone.

There is now a simple UI. Select White or Black and those color specks are gone!

It's not perfect. It only works on very small specks. Basically what it does is Clone Stamp them out.

Install the dll in the normal way. Then, restart Paint.NET and look in Effects > Photo > Remove Dust for the effect.

Download Here

For Paint.NET 3.5.11:

RemoveDust.zip

For Paint.NET 4.0:

http://forums.getpaint.net/index.php?/topic/28488-

I'm thinking "Plugin of the Year". Yes?

4

Share this post


Link to post
Share on other sites

Well done you get my vote ;) Must feel good to have a problem like that and just be able to knock out a plugin :(

1

Share this post


Link to post
Share on other sites

Must feel good to have a problem like that and just be able to knock out a plugin :(

Yeah, CodeLab is the best plugin ever.

Now, I can't speak for those who write canvas plugins, but I find that actually coding a plugin is the easy part. Coming up with the idea is the hard part.

In this case, I wrote it to save myself a ton of time.

Any time you find yourself doing the same steps multiple times, make a note of it. If you don't have the ability to code a plugin yourself, I'm sure someone would be able to automate those steps for you.*

And, thanks for the vote. :D

*Keeping in mind the limitations of the plugin system. ;)

0

Share this post


Link to post
Share on other sites

I have just used this plug-in on some old scans of mine with great results, thanks for sharing BoltBait :)

Vote #2 heading your way :D

0

Share this post


Link to post
Share on other sites

It makes me fatter? Other than that I'm sold! :)

0

Share this post


Link to post
Share on other sites
It makes me fatter?

Actually, I think its the pizza that does that. ;)

0

Share this post


Link to post
Share on other sites

For those of us interested in the development, but without asking anyone to reveal any "trade secrets" may I ask what toolkit was used to take the code above to compiled .dll?

 

Either way, one of the best, most useful plug-ins to any image management software I've seen anywhere.  THANK YOU !!!

0

Share this post


Link to post
Share on other sites

For those of us interested in the development, but without asking anyone to reveal any "trade secrets" may I ask what toolkit was used to take the code above to compiled .dll?

That would be CodeLab.

0

Share this post


Link to post
Share on other sites

^^ He's too modest. CodeLab is developed and maintained by @BoltBait (free to download, donations welcomed). Damned fine piece of kit it is too!

You'll find numerous excellent tutorials on BoltBait's website (link in his signature).

0

Share this post


Link to post
Share on other sites

This plug-in is great.  I'm a total noob, but would it be hard for me to duplicate this to eliminate black dots?

0

Share this post


Link to post
Share on other sites

This plug-in is great. I'm a total noob, but would it be hard for me to duplicate this to eliminate black dots?

Thanks. Here ya go...

// Name: Remove Black Dust
// Submenu: Photo
// Author: BoltBait
// URL: http://BoltBait.com/pdn
private UserBlendOps.LightenBlendOp lightenOp = new UserBlendOps.LightenBlendOp();
void Render(Surface dst, Surface src, Rectangle rect)
{
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
      for (int x = rect.Left; x < rect.Right; x++)
      {
         ColorBgra CurrentPixel = src[x,y];
         if (x>0) CurrentPixel = src[x-1,y];
         CurrentPixel = lightenOp.Apply(src[x,y], CurrentPixel);
         dst[x,y] = CurrentPixel;
      }
   }
}
0

Share this post


Link to post
Share on other sites

I am a total novice with codeLab, I have read about it on your website BB, but I am at a loss with this code, when I open codeLab  how much of the script (code?) that is already there  do I remove before I insert the above code you have provided? I tried to copy / paste this but ended up with errors at different lines. The removal of black dots is a useful tool to have with some of my scans too. 

You may have a virtual hug (or a rep point) if you can help me please :D

0

Share this post


Link to post
Share on other sites

How to use a codelab script (including the one above)

1) Highlight the above code block and press Ctrl-C.

2) Run Paint.NET and open the graphic you want to modify.

3) Effects > Advanced > Codelab

4) In codelab, Edit > Select All

5) Edit > Paste

After a second the effect will compile and run. If you like the effect, click OK to keep the changes.

1

Share this post


Link to post
Share on other sites

Thank you BoltBait, that worked :)

Have the promised Rep point for that. (and some cake)  :cake:

0

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  
Followers 0