【问题标题】:"Source pixel format is not supported by the filter" error in AForge.NETAForge.NET 中的“过滤器不支持源像素格式”错误
【发布时间】:2012-08-04 18:27:08
【问题描述】:

我正在尝试在 Aforge 中应用 Bradleys 阈值算法

每次我尝试处理图像时都会出现以下异常

throw new UnsupportedImageFormatException("源像素格式不 过滤器支持。");

在应用算法之前,我使用以下方法对图像进行了灰度化

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

算法调用代码

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

我在图像处理实验室尝试了正常的图像,它确实有效,但在我的系统上却不行。

知道我做错了什么吗?

【问题讨论】:

  • 你确定你的bradley方法真的接收到灰度过滤的图像吗?当我运行您的代码并直接在button2_Click 中的grayImage 上应用BradleyLocalThresholding 过滤器时(在更新pictureBox1.Image 之前),Bradley 过滤器按需要工作。

标签: c# aforge


【解决方案1】:

在这种情况下,我使用以下代码来获取更好的信息。它不能解决问题,但它至少提供了比 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);
}

【讨论】:

  • 非常感谢,帮我解决了一个问题!
  • @levi 不幸的是,虽然这帮助我找出了一个问题(我现在不记得是哪一个),但这不是问题中的问题。
  • 我有同样的问题,问题出在像素格式,支持的格式似乎是 8bpp 索引。非常感谢帮助方法,那段代码为我节省了很多工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-28
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多