views:

988

answers:

5

I have been trying to find a code snippet to do an unsharp mask in C# but cant find one that works or is complete. I found a PHP version but I would like to find one in C# before I go through all the hard work converting this from PHP.

I am just a beginner. Can anyone point me in the right direction?

A: 

See if this blog entry helps you in the right direction:

http://anand-vinay.blogspot.com/2008/01/unsharp-mask-in-cnet.html

Edit: Okay that blog entry did not work, sorry for the bad link.

I did find a complete application that you can download with source which has the code that I think you are looking for.

http://www.ctyeung.com/Csharp/index.html

Jason Heine
i found this too, but the codes has double quotes on it, is it wrongly paste ?
khalil
I updated my answer to include a full project you can download and check out the source, took some digging but finally found one.
Jason Heine
it has the codes that i need. many thanks to you.
khalil
Note that this is sharpening with a convolution filter, not with an unsharp mask as you specifically asked.
Lucas
+1  A: 

The AForge.NET Framework includes many image processing filters and support plugging your own. You can see it in action in their own Image Processing Lab application.


UPDATE: AForge.NET has a convolution-based sharpen filter (see convolution filters), but there's no mention of an unsharp mask filter per se. Then again, you can use the Gaussian blur filter and subtract the result from the original image, which is basically what the unsharp mask filter does. Or maybe the basic sharpen is enough for your needs.


UPDATE: Looked further, and AForge.NET does have a Gaussian sharpen which seems to be an implemenation of an unsharp mask filter, and you can control some parameters.

Lucas
actually i was looking for unsharp mask filter that i could change the settings (Amount, Radius, Threshold)
khalil
i updated my answer with the gaussian sharpen filter
Lucas
ill check the gaussian sharpen. btw does this library is free to use ? im having trouble understanding so many licensing types.
khalil
As I understand it, the 1.x libraries are GPL licensed, so your application would have to be GPL licensed, too. The 2.x use Lesser GPL (LPGL) which does not require this if you only link to the libraries. http://developer.kde.org/documentation/licensing/licenses_summary.html
Lucas
ohh ok. so meaning i can use it with my app (not sure if its commercial app since it has advertisement) but just state the library name in the copyright page right ?im going to work now, ill check the lib when i get home. at work i have to do JSP, and my personal project is .NET haha. thanks
khalil
for now im using this. but i will try to find the one just like the php version that i mentioned.
khalil
A: 

Christian Graus's Image Processing for Dummies with C# part 2 contains source code, and an explanation of how you can do unsharpen (assuming you mean smoothing). The whole series is an excellent introduction to image processing with GDI (in C#) and requires no external libraries.

Kris Erickson
In image processing, "unsharpen" is not smoothing. Despite it's name, it is a specific method of sharpening an image. And the term "mask" comes from the way it was done in darkrooms. It has nothing to do with "masks" as used in image-editing software such as Photoshop. It would be called a filter in PS, not a mask.
Lucas
+1  A: 

Would you care to use FFTs? Transform, remove or accentuate high freqs to taste, invert the transform, recombine with the original if desired? Hardly any licensing issues there, as FFT libraries abound.

Alternately, you can make up masks by hand, varying size and constants as you like, then convolve them with your image pixels (nested 'for' loops ...).

Here's a 3x3x1 mask as a text file with its dimensions given before the values:

//3x3x1

// x size

3

// y size

3

//z size

1

//z = 0

2 3 2

3 5 3

2 3 2

//end

This can be extended to 3 dimensions (hence the z size being given).

behindthefall
this one is too advanced for me. but ill check it. thanks.
khalil
A: 

The latest version of the open source C# Image Library has an unsharp mask filter (as well as gaussian blur, brightness/contrast etc) and is very easy to use.

You'll find a tutorial how to apply an unsharp mask here.

Fredrik