作者:GAO-XIANG
轉自:http://blog.csdn.net/xiang__jiangsu/article/details/8144304
AdaptiveSmoothing:圖像平滑處理,用于對圖像進行适度的平滑,再平滑噪聲的條件下保留邊緣效應,實作如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\0.jpg");
Bitmap bt1 = bt.Clone(new Rectangle(new Point(0,0),bt.Size),bt.PixelFormat);
pictureBox1.Image = bt;
// create filter
AForge.Imaging.Filters.AdaptiveSmoothing filter = new AForge.Imaging.Filters.AdaptiveSmoothing();
// apply the filter
filter.ApplyInPlace(bt1);
運作結果:
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyRQpkL1QTOz8lNyITM0kTM1MTMvw1Mw8CXxEjMxAjMvw1ckF2bsBXdvwFdl5mLuR2cj5Set1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
Add :将原始圖像和疊置圖像像素相加得到新圖像,我們通過紅色+黃色=橙色來展示運作結果:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
Bitmap bt1 = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
// 建立過濾器
AForge.Imaging.Filters.Add filter = new AForge.Imaging.Filters.Add(bt);
//圖像相加
Bitmap resultImage = filter.Apply(bt1);
運作結果:
AdditiveNoise:通俗的翻譯,我們可以了解為添加劑噪聲濾波器,在原始圖像的像素中添加一個随機值,随機值由IRandomNumberGenerator生成,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
pictureBox1.Image = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
// 建立随機數組
IRandomNumberGenerator generator = new UniformGenerator(new Range(-50, 50));
// 建立過濾器
AForge.Imaging.Filters.AdditiveNoise filter = new AForge.Imaging.Filters.AdditiveNoise(generator);
// 圖像處理
filter.ApplyInPlace(bt);
運作結果:
BackwardQuadrilateralTransformation:後向四邊形轉換,可以實作将原始圖像轉換到目标圖像的四邊形區域當中,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
Bitmap bt1 = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
// 定義四邊形角點
List<IntPoint> corners = new List<IntPoint>();
corners.Add(new IntPoint(99, 99));
corners.Add(new IntPoint(156, 79));
corners.Add(new IntPoint(184, 126));
corners.Add(new IntPoint(122, 150));
// create filter
AForge.Imaging.Filters.BackwardQuadrilateralTransformation filter = new AForge.Imaging.Filters.BackwardQuadrilateralTransformation(bt, corners);
// apply the filter
Bitmap newImage = filter.Apply(bt1);
運作結果:
BayerDithering:基于Bayer 矩陣的圖像有序抖動,實作如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
Bitmap bt1 = bt.Clone(new Rectangle(new Point(0,0),bt.Size),PixelFormat.Format8bppIndexed);
// 建立過濾器
AForge.Imaging.Filters.BayerDithering filter = new AForge.Imaging.Filters.BayerDithering();
// 圖像過濾
filter.ApplyInPlace(bt1);
運作結果:
BayerFilter:通過色彩傳感器建立色彩矩陣将灰階圖轉為彩色圖。
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\3.jpg");
//Bitmap bt1 = bt.Clone(new Rectangle(new Point(0,0),bt.Size),PixelFormat.Format8bppIndexed);
// 生成過濾器
BayerFilter filter = new BayerFilter();
// apply the filter
Bitmap rgbImage = filter.Apply(bt);
運作結果:
BilateralSmoothing:使用色彩和空間因子進行儲存邊緣效應,消除噪聲的雙向平滑。示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
// create filter
AForge.Imaging.Filters.BilateralSmoothing filter = new AForge.Imaging.Filters.BilateralSmoothing();
filter.KernelSize = 7;
//空間因子
filter.SpatialFactor = 10;
//色彩因子
filter.ColorFactor = 60;
filter.ColorPower = 0.5;
// apply the filter
filter.ApplyInPlace(bt);
運作結果:
BlobsFiltering:将一定大小的對象剔除,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.bmp");
// 建立過濾器
AForge.Imaging.Filters.BlobsFiltering filter = new AForge.Imaging.Filters.BlobsFiltering();
// 設定過濾條件(對象長、寬至少為70)
filter.CoupledSizeFiltering = true;
filter.MinWidth = 100;
filter.MinHeight = 80;
filter.ApplyInPlace(bt);
運作結果:
Blur:對圖像實施模糊變換。
BradleyLocalThresholding:局部門檻值處理,當像素值比鄰近窗體所有像素的均值低百分之t 時将該點取為黑,否者均為白。示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\2.jpg");
AForge.Imaging.Filters.BradleyLocalThresholding filter = new AForge.Imaging.Filters.BradleyLocalThresholding();
filter.ApplyInPlace(bt);
運作結果:
BrightnessCorrection :灰階矯正,若輸入的矯正數p為正,則将輸入圖像灰階值範圍變換為【0,255-p】,輸出範圍為【p,255】,當為負時輸入範圍【-p,255】,輸出範圍【0,255-p】。
CannyEdgeDetector:使用Canny邊緣檢測算子檢測邊緣,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
Bitmap bt1 = bt.Clone(new Rectangle(new Point(0, 0), bt.Size), System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
AForge.Imaging.Filters.CannyEdgeDetector filter = new AForge.Imaging.Filters.CannyEdgeDetector();
filter.ApplyInPlace(bt1);
運作結果:
CanvasCrop,CanvasFill,CanvasMove:對特定區域進行色彩填充,或對圖像進行整體移動。
ChannelFiltering:對彩色圖像RGB通道進行灰階過濾,在某以特定範圍的至将被保留或去除,使用如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
AForge.Imaging.Filters.ChannelFiltering filter = new AForge.Imaging.Filters.ChannelFiltering();
// 确定通道過濾範圍
filter.Red = new IntRange(0, 255);
filter.Green = new IntRange(100, 255);
filter.Blue = new IntRange(100, 255);
filter.ApplyInPlace(bt);
運作結果:
Closing:方法:對圖像中的單個對象進行膨脹,在進行侵蝕,由于膨脹會使本來不相連的獨立對象互相連接配接,使得即是侵蝕也依舊能保持對象的相連狀态。
ColorRemapping:與LevelsLinear不同,ColorRemapping可以對圖像進行非線性變換,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
byte[] map = new byte[256];
for (int i = 0; i < 256; i++)
{
map[i] = (byte)Math.Min(255, Math.Pow(2, (double)i / 32));
}
// create filter
AForge.Imaging.Filters.ColorRemapping filter = new AForge.Imaging.Filters.ColorRemapping(map, map, map);
// apply the filter
filter.ApplyInPlace(bt);
運作結果:
Connectedcomponentslabeling:通過為不同對象去不同顔色來差別圖像中的不同部分。
ConservativeSmoothing:使用矩陣視窗在圖像中搜尋,将視窗中最小或最大值用平均值來代替以此消除噪聲。
Convolution :卷積操作,通過設定不同的卷積矩陣獲得不同的圖像處理效果,如下面示例:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
pictureBox1.Image = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
// 定義卷積核
int[,] kernel = {
{ -2, -1, 0 },
{ -1, 1, 1 },
{ 0, 1, 2 } };
//建立過濾器
AForge.Imaging.Filters.Convolution filter = new AForge.Imaging.Filters.Convolution(kernel);
filter.ApplyInPlace(bt);
運作結果:
CornersMarker :通過角點算法探測并高亮顯示角點,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.bmp");
// create corner detector's instance
SusanCornersDetector scd = new SusanCornersDetector();
// create corner maker filter
AForge.Imaging.Filters.CornersMarker filter = new AForge.Imaging.Filters.CornersMarker(scd, Color.Black);
// apply the filter
filter.ApplyInPlace(bt);
運作結果:
Crop :對原始圖像确定矩形邊界點并生成新圖。
Difference :原始圖像與疊置圖像的差分運算。
DifferenceEdgeDetector:在四方向上計算像素的差分最大值,是以獲得邊緣線(原始圖像為灰階圖),示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
pictureBox2.Image = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
// create filter
AForge.Imaging.Filters.DifferenceEdgeDetector filter = new AForge.Imaging.Filters.DifferenceEdgeDetector();
// apply the filter
filter.ApplyInPlace(bt);
運作結果:
Dilatation:膨脹算法,原理十分簡單,去一定的臨近像素,并将;臨近像素最大值賦給目前像素。
Edges:簡單的邊緣探測。
Erosion :圖像侵蝕,與膨脹算法完全相反,将臨近像素最小值賦給目前點。
EuclideanColorFiltering:歐幾裡德色彩過濾,使用RGB球體對色彩進行過濾。
ExtractBiggestBlob:從圖像中裁剪出最大的對象。
ExtractChannel:獲得彩色圖像中的一個通道,并傳回灰階圖像。
FillHoles:用于填補空洞。
FilterIterator:用于過濾疊代操作,該類本身并未實作過濾功能,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
FiltersSequence filterSequence = new FiltersSequence();
filterSequence.Add(new HitAndMiss(
new short[,] { { 0, 0, 0 }, { -1, 1, -1 }, { 1, 1, 1 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { -1, 0, 0 }, { 1, 1, 0 }, { -1, 1, -1 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { 1, -1, 0 }, { 1, 1, 0 }, { 1, -1, 0 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { -1, 1, -1 }, { 1, 1, 0 }, { -1, 0, 0 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { 1, 1, 1 }, { -1, 1, -1 }, { 0, 0, 0 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { -1, 1, -1 }, { 0, 1, 1 }, { 0, 0, -1 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { 0, -1, 1 }, { 0, 1, 1 }, { 0, -1, 1 } },
HitAndMiss.Modes.Thinning));
filterSequence.Add(new HitAndMiss(
new short[,] { { 0, 0, -1 }, { 0, 1, 1 }, { -1, 1, -1 } },
HitAndMiss.Modes.Thinning));
// 進行十次疊代
AForge.Imaging.Filters.FilterIterator filter = new AForge.Imaging.Filters.FilterIterator(filterSequence, 10);
Bitmap newImage = filter.Apply(bt);
運作結果:
GammaCorrection:基于公式:V(output)=V(input)^g,g為改正系數。
GaussianBlur,GaussianSharpen:高斯模糊,高思銳化。
Grayscale :圖像的灰階變換,R\G\B三通道以一定的比值求和獲得像素灰階值。
GrayscaleToRGB:将灰階圖轉換為彩色圖。
HistogramEqualization:直方圖均衡化,示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
// 建立過濾器
AForge.Imaging.Filters.HistogramEqualization filter = new AForge.Imaging.Filters.HistogramEqualization();
filter.ApplyInPlace(bt);
運作結果:
HomogenityEdgeDetector :邊緣探測。
IterativeThreshold:疊代門檻值法,最後生成非黑即白的圖像,具體算法過程為:1)設定初始門檻值,小于門檻值取背景色,大于門檻值取對象色 2)門檻值的一半繼續疊代運算 3)當上一門檻值與本門檻值隻差絕對值小于某值時停止運算。
OilPainting:處理原理很簡單:首先确定一定的搜尋面積,在搜尋區域内尋找出現頻率最高的灰階值,找到後将其值指派給目前搜尋中心像素。示例如下:
Bitmap bt = new Bitmap(@"C:\Users\GAOXIANG\Desktop\1.jpg");
// 确定畫筆為15
OilPainting filter = new OilPainting(30);
// apply the filter
filter.ApplyInPlace(bt);
運作結果:
Opening:相當于對圖像先進行侵蝕後進行膨脹。
Pixellate:通過産生一定的矩形大小,使矩形中的像素具有相同的像素值,以此産生類似于馬賽克的圖像效果。
QuadrilateralTransformation:提取原圖像中的四邊形區域的圖像資訊。
StereoAnaglyph:用于産生立體視圖,提供的初始影像應當具有不同的視角,示例如下:
// create filter
StereoAnaglyph filter = new StereoAnaglyph( );
// set right image as overlay
filter.Overlay = rightImage
// apply the filter (providing left image)
Bitmap resultImage = filter.Apply( leftImage );
運作結果:
TexturedFilter:為圖檔建立紋理。
Threshold:基于特定門檻值的圖像二值化,當像素值大于門檻值,為白色,小于門檻值則取黑色。
WaterWave:使圖像具有水波紋效果。