【代码阅读摘记】阅读AForge.NET (1)

AForge.Imaging.Filters定义了3个公共接口

public   interface  IFilter

The interface defines the set of methods, which should be provided by all image processing filters. Methods of this interface keep the source image unchanged and return the result of image processing filter as new image.

定义的操作集合:

Bitmap Apply( Bitmap image );
Bitmap Apply( BitmapData imageData );

 

public   interface  IInPlaceFilter

The interface defines the set of methods, which should be implemented by filters, which are capable to do image processing directly on the source image. Not all of image processing filters can be applied directly to the source image - only filter, which do not change image's dimension and pixel format, can be applied directly to the source image.

定义的操作集合:

void  ApplyInPlace( Bitmap image );
void  ApplyInPlace( BitmapData imageData );

 

public   interface  IInPlacePartialFilter

The interface defines the set of methods, which should be implemented by filters, which are capable to do image processing directly on the source image. Not all of image processing filters can be applied directly to the source image - only filter, which do not change image's dimension and pixel format, can be applied directly to the source image. The interface also support partial image filtering, allowing to specify image rectangle, which should be filtered.

定义的操作集合:

void  ApplyInPlace( Bitmap image, Rectangle rect );
void  ApplyInPlace( BitmapData imageData, Rectangle rect );

 

6个抽象类实现了以上3个接口

FilterAnyToGray : IFilter
FilterAnyToAnyUsingCopy : IFilter, IInPlaceFilter
FilterAnyToAnyNewSameSize : IFilter
FilterGrayToGrayUsingCopy : IFilter, IInPlaceFilter
FilterGrayToGrayNewSameSize : IFilter
FilterColorToColor : IFilter, IInPlaceFilter

 

public   abstract   class  FilterAnyToGray : IFilter

The abstract class is the base class for all filters, which accept color or grayscale images and return grayscale image as a result. These filters do not change dimension of source image. Filters based on this class cannot be applied directly to the source image. Instead of this they provide output image as a result of image processing routine.

实现了IFilter中的Apply的2个版本的Apply方法。提供了一个抽象方法,该抽象方法被已经实现的Apply方法调用,具体实现留给实体类来完成:

protected   abstract   unsafe   void
ProcessFilter( BitmapData sourceData, BitmapData destinationData );

 

FilterAnyToAnyUsingCopy : IFilter, IInPlaceFilter

The abstract class is the base class for all filters, which can be applied to color and grayscale images without changing their pixel format and image dimension. The base class is used for filters, which can not do direct manipulations with source image. To make effect of in-place filtering, these filters create a background copy of the original image (done by this base class) and then do manipulations with it putting result back to the original source image.

实现了IFilter和IInPlaceFilter中的方法,使得这类Filter支持2种模式的图像处理(原图和拷贝)。提供一个抽象方法,具体实现留给实体类完成:

protected   abstract   unsafe   void  
ProcessFilter( IntPtr sourceData, BitmapData destinationData );

相对于在上一个抽象Filter中定义的ProcessFilter,该抽象方法的第一个参数是一个指针,该指针指向待处理图像的第一个扫描行。

FilterAnyToAnyNewSameSize是过期的抽象类,已经被FilterAntToAnyUsingCopy所代替
FilterGrayToGrayNewSameSize是过期的抽象类,已经被FilterGrayToGrayUsingCopy所代替

其余的抽象类不再赘述,大致的实现方式都是类似的。这些抽象的基类主要区别在于3个方面:1.输入图像和输出图像的色彩上的区别 2.是否在原图上进行图像处理 3.处理区域为全图还是局部

关于Filter的具体算法实现全部放在这些抽象基类的实体子类中。通过以上的阅读工作,已经可以了解到AForge的Filter命名空间的设计方法。正文中出现的英文均直接摘自AForge的代码注释。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值