:: AForge.NET Framework :: Articles :: Forums ::

Problem with demosaicing .NET

The forum is to discuss topics related to different areas of image processing and computer vision.

Problem with demosaicing .NET

Postby DhlIntern » Mon May 01, 2017 9:11 am

Hi all,

I'm pretty new to all of this so let me explain briefly. I'm an intern working at a Holographic Laboratory. They want me to write them a program that can control a 1394 camera whilst converting the images it makes to a demosaiced image.

I've got knowledge over the past few months in how this works & all but there is something I cant figure out.

When using the AFORGE demosaicing algorithm the images come out perfect when using random images I find online with the bayer filter on it.
When I use this 1394 camera the image's will be saved as a bitmap. Now whenever I try to load in ths bitmap image it gives me an error code with "UnsupportedImageFormatException".
I've read you have to convert the image to a greyscale 8bbp image which I do.. My source code is right down here, can someone tell me what i'm doing wrong?

When I convert the image to a JPEG the algorithm works fine, but the image comes out distorted with the bayer filter still visible..

Code: Select all
  public Bitmap Demosaic(string file)
            Bitmap bitmap = new Bitmap(file);
            BayerFilterOptimized filter = new BayerFilterOptimized();
            Bitmap bMap = AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format8bppIndexed);
            var imag = Grayscale.CommonAlgorithms.BT709.Apply(bMap);
            filter.Pattern = BayerPattern.BGGR;
            return filter.Apply(imag);
Posts: 2
Joined: Mon May 01, 2017 9:05 am

Re: Problem with demosaicing .NET

Postby andrew.kirillov » Tue May 02, 2017 7:08 am


You don't need this line:
Code: Select all
Bitmap bMap = AForge.Imaging.Image.Clone(bitmap, PixelFormat.Format8bppIndexed);

Just apply grayscale filter to the loaded image.
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Problem with demosaicing .NET

Postby DhlIntern » Tue May 02, 2017 7:53 am


Thanks for the reply. It worked!
Posts: 2
Joined: Mon May 01, 2017 9:05 am

Return to Image Processing and Computer Vision