5

I'm trying to apply Bradleys thresholding algorithm in Aforge

Everytime I try to process the image I get the exception below

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

I grayscaled the image using the below method 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;
}

The code for the algorithm call

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

I tried the sane image in image processing lab and it did work but not on my system.

Any idea what I'm doing wrong?

4

1 に答える 1

5

このような場合、次のコードを使用してより良い情報を取得しました。問題は解決しませんが、少なくとも AForge が単独で行うよりも役立つ情報が得られます。

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)));
        }
    }
}

あなたの場合、次のように使用できます。

public void bradley(ref Bitmap tmp)
{  
    BradleyLocalThresholding filter = new BradleyLocalThresholding();
    filter.AssertCanApply( tmp.PixelFormat );
    filter.ApplyInPlace(tmp);
}
于 2012-08-13T13:26:15.007 に答える