Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Bitmap SobelFilter(Bitmap original)
- {
- int[][] Gx = new int[][] { //maska po X
- new int[] {-1,0,1},
- new int[] {-2,0,2},
- new int[] {-1,0,1},
- };
- int[][] Gy = new int[][] { //maska po Y
- new int[] {1,2,1},
- new int[] {0,0,0},
- new int[] {-1,-2,-1},
- };
- Bitmap output = new Bitmap(original);
- FastBitmap temp = new FastBitmap(output); //FastBitmap - szybsze obrabianie pikseli
- FastBitmap input = new FastBitmap(original);
- temp.LockImage();
- input.LockImage();
- for (int i = 1; i < original.Height - 1; i++) //pętla po wierszach
- {
- for (int j = 1; j < original.Width - 1; j++) //pętla po kolumnach (już konkretny pixel)
- {
- double new_x = 0, new_y = 0;
- double c;
- for (int hw = -1; hw < 2; hw++) //po macierzy
- {
- for (int wi = -1; wi < 2; wi++)
- {
- c = input.GetPixel(j + wi, i + hw).B;
- new_x += Gx[hw + 1][ wi + 1] * c;
- new_y += Gy[hw + 1][ wi + 1] * c;
- }
- }
- int value = Convert.ToInt32(Math.Sqrt(new_x * new_x + new_y * new_y))%255;
- Color tempcolor = Color.FromArgb(value, value, value);
- temp.SetPixel(j, i, tempcolor);
- }
- }
- temp.UnlockImage();
- input.UnlockImage();
- return output;
- }//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement