Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Drawing;
- namespace WindowsFormsApplication1
- {
- class MatrixFilter : Filters
- {
- protected float[,] kernel = null;
- protected MatrixFilter() { }
- public MatrixFilter(float[,] kernel)
- {
- this.kernel = kernel;
- }
- protected override Color calculateNewPixelColor(Bitmap sourceImage, int x, int y)
- {
- int radiusX = kernel.GetLength(0) / 2;
- int radiusY = kernel.GetLength(1) / 2;
- float resultR = 0;
- float resultG = 0;
- float resultB = 0;
- for (int l = - radiusY; l <= radiusY; l++)
- {
- for (int k = - radiusX; k <= radiusX; k++)
- {
- int idX = Clamp(x + k, 0, sourceImage.Width - 1);
- int idY = Clamp(y + l, 0, sourceImage.Height - 1);
- Color neighborColor = sourceImage.GetPixel(idX, idY);
- resultR += neighborColor.R * kernel[k + radiusX, l + radiusY];
- resultG += neighborColor.G * kernel[k + radiusX, l + radiusY];
- resultB += neighborColor.B * kernel[k + radiusX, l + radiusY];
- }
- }
- return Color.FromArgb(
- Clamp((int)resultR, 0, 255),
- Clamp((int)resultG, 0, 255),
- Clamp((int)resultB, 0, 255)
- );
- }
- protected override void CalcInten(Bitmap sourceImage)
- {
- //throw new NotImplementedException();
- }
- protected override void CalcAvg(Bitmap sourceImage)
- {
- //throw new NotImplementedException();
- }
- protected override Bitmap Open(Bitmap sourceImage, BackgroundWorker worker)
- {
- return sourceImage;
- }
- protected override Bitmap Tophat(Bitmap sourceImage, Bitmap resultImage, BackgroundWorker worker)
- {
- return sourceImage;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement