"Source pixel format is not supported by filter error" in AForge.NET

I am trying to apply the Bradleys threshold algorithm in Aforge

Every time I try to process an image, I get an exception below

throw new UnsupportedImageFormatException ("The source pixel format is not supported by the filter.");

I grayed out the image using the method below before applying the algorithm

private void button2_Click(object sender, EventArgs e) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721); Bitmap grayImage = filter.Apply(img); pictureBox1.Image = grayImage; } 

Code to call the algorithm

 public void bradley(ref Bitmap tmp) { BradleyLocalThresholding filter = new BradleyLocalThresholding(); filter.ApplyInPlace(tmp); } 

I tried a sane image in an image processing lab and it really worked, but not on my system.

Any idea what I'm doing wrong?

+4
source share
1 answer

I used the following code to get more details in such cases. This does not fix the problem, but at least provides more useful information than AForge itself.

 namespace AForge.Imaging.Filters { /// <summary> /// Provides utility methods to assist coding against the AForge.NET /// Framework. /// </summary> public static class AForgeUtility { /// <summary> /// Makes a debug assertion that an image filter that implements /// the <see cref="IFilterInformation"/> interface can /// process an image with the specified <see cref="PixelFormat"/>. /// </summary> /// <param name="filterInfo">The filter under consideration.</param> /// <param name="format">The PixelFormat under consideration.</param> [Conditional("DEBUG")] public static void AssertCanApply( this IFilterInformation filterInfo, PixelFormat format) { Debug.Assert( filterInfo.FormatTranslations.ContainsKey(format), string.Format("{0} cannot process an image " + "with the provided pixel format. Provided " + "format: {1}. Accepted formats: {2}.", filterInfo.GetType().Name, format.ToString(), string.Join( ", ", filterInfo.FormatTranslations.Keys))); } } } 

In your case, you can use it like:

 public void bradley(ref Bitmap tmp) { BradleyLocalThresholding filter = new BradleyLocalThresholding(); filter.AssertCanApply( tmp.PixelFormat ); filter.ApplyInPlace(tmp); } 
+5
source

All Articles