Friday, March 4, 2011

C# :- Imaging ( AForge.net )

If you are doing some image processing there is an interesting and cool open source project called AForge.net .  It contains many routines and filters for image processing.  I started playing with Glyph’s Recognition,  glyph’s recognition engine is provided by AForge Framework.   There is  GRATF  (Glyph Recognition and Tracking Framework)  project  based upon  AForge framework.  GRATF framework mainly deals with the Glyph recognition algorithm and glyph tracking  , utilizing the AForge.Net  image processing library. 

To  get started with Glyph recognition , download the GRATF source code from source code repository at Google :-

http://code.google.com/p/gratf/downloads/list 

After downloading the source  you can start exploring the  code. There is an application that comes with download called Glyph’s Recognition Studio.  It lets you to specify the particular glyph to be recognized and also support 2d augmentation , that lets you to place a particular image over the recognized glyph.   Implementation and description of the glyph recognition algorithm is described at :-  http://www.aforgenet.com/articles/glyph_recognition/.

Glyph to be recognised is created on a white paper with outermost white border , then black border with glyph inside.

Glyph’s recognition make use of various image filters from the AForge Framework. It starts all with the bitmap to be processed , its the managed bitmap captured from the source . Bitmap image is converted into Unmanaged image using the UnmanagedImage class of AForge.Imaging namespace.  UnmanagedImage class takes the BitmapData as a parameter in its constructor and converts the Bitmap image into unmanaged image. With unmanaged image we do not have to lock image bits before processing the image pixels , as with managed bitmap image , so overhead of locking and unlocking bitmap is avoided

BitmapData bitmapData = image.LockBits( new Rectangle( 0, 0, image.Width, image.Height ),
                ImageLockMode.ReadOnly, image.PixelFormat );

UnmanagedImage unmanagedImg = new UnmanagedImage( bitmapData ) ;

With our unmanaged image , first step is to apply the GrayScale filter to unmanaged image . GrayScale filter processes the image pixels and returns only the pixels within gray range from 0 to 1 . Gray range is from complete white to black and varied gray component in-between . As we are only concerned with the intensity of the pixels, so we discard the colour information  by applying the GrayScale filter of AForge framework.

UnmanagedImage grayImage = UnmanagedImage.Create( image.Width, image.Height, PixelFormat.Format8bppIndexed );
Grayscale.CommonAlgorithms.BT709.Apply( image, grayImage );

After we have reduced the image with only gray intensity pixels, we apply DifferenceEdgeDetector filter on the grayscale image to detect the edges in the image .

DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
           UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);

Then we apply Threshold filter to the image to convert gray range pixels into  black or white pixels using the threshold value taken as constructor parameter by Threshold filter.

Threshold thresholdFilter = new Threshold(40);
           thresholdFilter.ApplyInPlace(edgesImage);

We use BlobCounter class to get all the detected blobs in the image of particular size and width.

BlobCounter blobCounter = new BlobCounter();
          blobCounter.MinHeight = 48;
          blobCounter.MinWidth = 48;

blobCounter.ProcessImage(edgesImage);
           Blob[] blobs = blobCounter.GetObjectsInformation();

We iterate over all the blobs detected and use SimpleShapeChecker to check if the blob is of a particular shape.

List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
List<IntPoint> corners = null;

if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
              

After passing the IsQuadrilateral check of SimpleShapeChecker we calculate the average brightness of the pixels from both the sides of the edges of Quadrilateral . If the average brightness exceeds a predefined value we further process to get the glyph value.  We apply QuadrilateralTransformation filter on the corners of the Quadrilateral and get the rectangle image of the glyph.

Once we have the rectangle image of the glyph we can iterate over all the pixels of the image using the UnmanagedImage pixel byte pointer and calculate the intensity of the pixels for the each cell of the image and then checking it with the glyph database for glyph recognition.

http://www.aforgenet.com/projects/gratf/

http://www.aforgenet.com/projects/gratf/code_samples.html

Wednesday, March 2, 2011

Silverlight Video Streaming and IIS Smooth streaming

Previously , I have written a blog about the WCF streaming  (here) .  I have got many responses on this blog entry and now I will further explore the streaming with Silverlight streaming and the IIS smooth streaming .

Silverlight streaming make use of Microsoft Expression encoder to package the media content with a silverlight media template . Microsoft Expression encoder is the application which comes with the expression suit applications from Microsoft.  It lets you to adjust the bitrates and resolution of your media content and package it along with the silverlight media template to play it in. Microsoft expression encoder lets you to publish the media content to the silverlight services and azure cloud.

We can download the expression encoder from here download encoder . Hosting of media contents with silverlight services has been discontinued as it was in beta phase. Now we have option of hosting our media content on Azure.

These are the some links to get started with the silverlight streaming and azure media hosting using Microsoft Expression Encoder .

Silverlight Services hosting (Discontinued)

Hosting videos on Azure

Apart for hosting our media on the Azure cloud , we can host the media on our web server and take the benefit of the  IIS Smooth streaming feature .  Here are some links that will get you started with configuring and using IIS Smooth streaming.

Getting started :- IIS Smooth streaming

IIS Smooth streaming sample application

Installing and configuring IIS Smooth streaming

Smooth Streaming fundamental

There are many possibilities to build the media content delivery system on top of these streaming choices.                          Happy streaming…..