C# &引用;“过滤器”不支持源像素格式;AForge.NET中的错误
我正在尝试将布拉德利的阈值算法应用到一个大的例子中 每次我尝试处理图像时,都会出现下面的异常 抛出新的UnsupportDimageFormatException(“源像素格式不可用”) 由过滤器支持。”) 在应用算法之前,我使用下面的方法对图像进行灰度缩放C# &引用;“过滤器”不支持源像素格式;AForge.NET中的错误,c#,aforge,C#,Aforge,我正在尝试将布拉德利的阈值算法应用到一个大的例子中 每次我尝试处理图像时,都会出现下面的异常 抛出新的UnsupportDimageFormatException(“源像素格式不可用”) 由过滤器支持。”) 在应用算法之前,我使用下面的方法对图像进行灰度缩放 private void button2_Click(object sender, EventArgs e) { Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
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);
}
我在图像处理实验室试用了sane图像,它确实有效,但在我的系统上没有
你知道我做错了什么吗?我使用了下面的代码,以便在这种情况下获得更好的信息。它并不能解决问题,但至少它提供了比一个论坛本身更多的有用信息
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)));
}
}
}
您确定您的
bradley
方法确实接收到灰度过滤图像吗?当我运行您的代码并直接在按钮2中的灰度图像上应用BradleyLocalThresholding
过滤器时(在更新pictureBox1.Image
之前),Bradley过滤器可以按需工作。非常感谢,帮助我解决了一个问题@levi不幸的是,虽然这帮助我解决了一个问题(我现在不记得是哪一个),但这不是问题中的问题。我也有同样的问题,问题是像素格式,支持的格式似乎是8bpp索引。非常感谢你的帮助,这段代码为我节省了很多工作
public void bradley(ref Bitmap tmp)
{
BradleyLocalThresholding filter = new BradleyLocalThresholding();
filter.AssertCanApply( tmp.PixelFormat );
filter.ApplyInPlace(tmp);
}