【问题标题】:Image filtering order图像过滤顺序
【发布时间】:2015-08-21 21:28:50
【问题描述】:

我正在尝试编写一个简单的照片编辑器,它应该允许用户将各种过滤器应用于所选图像。 如何使用这些过滤器为任何用户操作顺序获得与在 AcdSee、IrfanView 等中相同的结果图像?

byte[] ApplyFilter1(byte[] img, int step)
{

    for(int i = 0; i < img.Length; i++)
    {
        img[i]+=step;//changing brightness
    }
    return img;
}

byte[] ApplyFilter2(byte[] img, int step)
{

    for(int i = 0; i < img.Length; i++)
    {
        img[i]*=step;//changing whatever
    }
    return img;
}

//1 situation - user sets filter1 and then filter2
img = ApplyFilter1(img, 10);
img = ApplyFilter2(img, 10);

//2 situation - user sets filter2 and then filter1
img = ApplyFilter2(img, 10);
img = ApplyFilter1(img, 10);

有没有默认的申请顺序? 例如

  1. 亮度
  2. 对比度
  3. 伽玛校正 ...

提前致谢!

【问题讨论】:

  • 我强烈怀疑你的前提。您应用图像过滤器的顺序将(并且应该)几乎总是会产生差异。我不知道 AcdSee 但 Photoshop 和其他程序。而且,是的,有一个过滤器总是应该首先应用(根据需要):Gamma 校正首先出现,然后才出现,希望即使那样 Contrast 和 颜色变化和饱和度,也许还有亮度..但我不明白你想要什么:如果用户做事,那么他应该可以随心所欲,不?很好的建议,并希望保留原件以防止最坏的情况发生..

标签: c# image-processing


【解决方案1】:

您可以通过为每个过滤器定义一个优先级,然后进行相应的处理来实现此目的:

您的图片:

public class Picture
{
    public int Width, Height;

    public Color[] GetPixels()
    {
        // ...
    }
}

您的过滤器,以及一些派生示例:

public abstract class Filter
{
    public virtual int Priority
    {
        get { return 0; }
    }

    public abstract Picture Apply(Picture picture);
}

public class BrightnessFilter : Filter
{
    public override int Priority
    {
        get { return 1; }
    }

    public override Picture Apply(Picture picture)
    {
        throw new NotImplementedException();
    }
}

public class ContrastFilter : Filter
{
    public override int Priority
    {
        get { return 2; }
    }

    public override Picture Apply(Picture picture)
    {
        throw new NotImplementedException();
    }
}

您的图片处理器,在应用过滤器之前先对它们进行排序:

public class Processor
{
    public List<Filter> Filters { get; set; }

    public Pitcure Process(Picture picture)
    {
        var filters = Filters.OrderBy(s => s.Priority);
        var result = picture;
        foreach (var filter in filters)
        {
            result = filter.Apply(result);
        }

        return result;
    }
}

这是一个非常简单的方法,您可以进一步增强:D

PS:

您可以询问这些类型的过滤器应按什么顺序应用@https://graphicdesign.stackexchange.com/

【讨论】:

    猜你喜欢
    • 2018-08-27
    • 2017-10-29
    • 2019-02-05
    • 1970-01-01
    • 2011-12-14
    • 2017-09-10
    • 2014-11-15
    • 2014-05-17
    相关资源
    最近更新 更多