Image Processing Lab in C#

Introduction

Image Processing Lab is a simple tool for image processing, which includes different filters and tools to analyze images available in the AForge.NET framework. It's easy to develop your own filters and to integrate them with the code or use the tools in your own application. The following filters are implemented in the AForge.NET framework and demonstrated in the application:

You can create (save and load) your own convolution filters or filters based on standard mathematical morphology operators. Colorized grid makes it very convenient to work with custom convolution filters.

A preview window allows you to view the results of changing filter parameters on the fly. You can scroll an image using the mouse in the preview area. All filters are applied only to the portion of the image currently viewed to speed up preview.

A PhotoShop-like histogram allows you to get information about mean, standard deviation, median, minimum and maximum values.

The program allows you to copy to or paste from clipboard, save and print images.

Using the Code

Most filters are designed to work with 24bpp RGB images or with grayscale images. In the case of grayscale images, we use PixelFormat.Format8bppIndexed with color palette of 256 entries. To guarantee that your image is in one of the formats, you can use the following code:

Suppose, you want to apply a series of filters to an image. The straight way to do it is to apply filters one after another, but it's not very likely in the case of 3 or more filters. All filters implement the IFilter interface, so it allows us to create a collection of filters and apply it at once to an image (besides, the collection will also save us from disposing routines on intermediate images):

HSL Filters

Using HSL color space is more obvious for some sorts of filters. For example, it's not very clean, how to adjust saturation levels of an image using RGB color space. But it can be done easily, using HSL color space:

It's possible to get much more interesting results using HSL filtering. For example, we can preserve only the specified range of hue values and desaturate all others out of the range. So, it will lead to a black and white image with only some regions colored.

Mathematical Morphology Filters

There are many tasks that can be accomplished using mathematical morphology filters. For example, we can reduce noise on binary images using erosion, or we can separate some objects with the filter. Using dilatation, we can grow some parts of our interest on the image. One of the most interesting morphological operators is known as Hit & Miss. All other morphological operators can be expressed from the Hit & Miss operator. For example, we can use it to search for particular structures on the image:

Blob Counter

Blob counter is a very useful feature and can be applied in many different applications. What does it do? It can count objects on a binary image and extract them. The idea comes from "Connected components labeling," a filter that colors each separate object with a different color. Let's look into a small sample:

YCbCr Filtering

YCbCr filters are provided with similar functionality to RGB and HSL filters. The YCbCr linear correction filter performs as its analogues from other color spaces, but operates with the Y, Cb and Cr components respectively, providing us with additional convenient ways of color correction. The next small sample demonstrates the use of the YCbCr linear filter and the use of in-place filtering: the feature, which allows you to filter a source image instead of creating a new result image, is as follows:

Perlin Noise Filters

Perlin noise has many applications and one of the most interesting of them is the creation of different effects, like marble, wood, clouds, etc. Application of such effects to images can be done in two steps. The first step is to generate effect textures and the second step is to apply the textures to the particular image. Texture generators are placed into the Textures namespace of the library, which contains generators for such effects as clouds, wood, marble, labyrinth and textile. All these texture generators implement the ITextureGenerator interface. For applying textures to images, there are three filters. The fist one, Texturer, is for texturing images. The second, TexturedFilter, allows application of any other filter to an image using the texture as a mask. The third, TexturedMerge, allows merging of two images using the texture as a mask.

AForge.NET Framework

The Image Processing Lab application is based on the AForge.NET framework, which provides all the filters and image processing routines available in the application. To get more information about the framework, you may read the dedicated article on The Code Project or visit the project's home page, where you can get all the latest information about it, participate in a discussion group or submit issues or requests for enhancements.

Conclusion

I suppose the code may be interesting for someone who would like to start studying image processing or for filters/effects developers. As for me, I'll use the tool for my further research in computer vision. Besides, the library helped me very much in successfully finishing my bachelor work.

History

[08.03.2007] - Version 2.4.0

Application converted to .NET 2.0;

Integrated with AForge.NET framework.

[13.06.2006] - Version 2.3.0

In place filter interface introduced, which allows filter application on the source image;

License

Share

About the Author

Started software development at about 15 years old and it seems like now it lasts most part of my life. Fortunately did not spend too much time with Z80 and BK0010 and switched to 8086 and further. Similar with programming languages – luckily managed to get away from BASIC and Pascal to things like Assembler, C, C++ and then C#. Apart from daily programming for food, do it also for hobby, where mostly enjoy areas like Computer Vision, Robotics and AI. This led to some open source stuff like AForge.NET, Computer Vision Sandbox, cam2web, ANNT, etc.

Going out of computers I am just a man loving his family, enjoying traveling, doing some sports, a bit of books, a bit of movies and a mixture of everything else. Always wanted to learn playing guitar, but it seems like 6 strings are much harder than few dozens of keyboard’s keys. Will keep progressing ...

Comments and Discussions

Yes, I would like to ask you the same question: "What kind of comparison do you want and what do you want to receive as a result?". The Difference filter is one of possible ways to compare images. Do you want to have some sort of numeric value or ... ? What is the task you are trying to solve?

It depends on what exactly you would like to get. At this point there is no ready complete solution for your task in this library. But you may find useful different color filters, which allow you to search for something in certain range of colors. Also you may find useful such algorithms like binarization, morphology, edge detectors, etc.

As for me I do not have the sample code on watermarking algorithm using wavelet transformation at this point. But I would love to study this topic and do some research in this area.

One small comment to your post. Development forums and other similar communities mostly serve as a place where you may get some help. But such requests like "Give me this as soon as possible" or "I need it urgently" do not like very polite and may lead to the fact that will get nothing. More of it, try to communicate, share with ideas, collect information, do your own research instead of just asking for a ready sample, what is the easiest way, but less valuable.

Well, first of all thanks for your comment about my post. But I think that there's a misunderstanding. I asked my younger sister for writing the post and she got some mistake while expressing my mind. The statement "give me this as soon as possible" means "I'm looking forward to receving your reply".
And the most important thing is I don't want to reuse a ready sample on my research. In watermarking field, there are so many kind of algorithm for you to study, I did my project by myself and then I want to search for some other sample code in order to compare the result with my work. Yes, just because that.
One more thing I remark while searching in this forum is there're some sample code were called "watermarking" or relate to this word but do not a really watermarking. It's just blend an image or a text to host image without any approach to protect the watermark as well as show the copyright. I suppose that they should be classified separatly.
Thanks and best regard

I have downloaded your library and done some experimentation with the Image Processing Lab sample. It looks very promising. For my project, I have a bitmap image of an object that is shaped roughly like a doughnut. I want to find the center of gravity for this object, then I want to find the axis of elongation. I think the Threshold, Edge detector and the Thinner filters will be applicable. Does anyone have any suggestions?

Setting a bunch of variables on one line like this is pretty ugly. This creates several ints, with names like t, ir, jr, etc. They will all default to 0. r will be set to the value of size, shifted right by 1. A binary shift moves the values across, so if you have the binary number 001100, then that value << 1 is 011000 and that value >> 1 is 000110 ( where the leading zeros are obviously meaningless ).

This has the effect of multiplying or dividing by 2. 10 is 2, and 1 is 1, 100 is 4.

Yes, it's true if you have more meaningful variables - it's better to split them into several lines, so it is much easer to understand them. But splitting into several lines such variables like loop indexes may look ugly too.

on closer inspection that hunch i had about it not being completely black is correct, i was running an edge detector over some text and on some letter combition it was connected with very dark but not black(like 16 instead of 0), is there some sort of thresholding i can do with the blob detector?

I did work out that mode thing as i stated in my first post, and running from your example i got horizontal line to be thinned, but all others directions don't seem to be working. my last attempt at it

Could you please point me in the right direction. What would be a good way to compare two images and in some way (perhaps using a circle of sorts) highlight the differences between the two on one of the images.

You may find something to think about in one of my other articles: Motion Detection Algorithms[^] - it describes how to get difference and highlight it.

The quick idea is:
1 - Use the Difference filter to get difference image;
2 - Apply Threshold filter to the difference image to binarize it and extract areas of significant difference;
3 - Use one of edge detector filters to get edges of regions;
4 - Put the above edges on of the images.

I could try to help, but on C#. What is the difficulty for you? VB.NET implementation or the method itself? If it is the second, than you may take a look at ColorFiltering filter in the library - it is very similar to the filter you are interested in.