Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public MyPixel[,] ExtraireMatrice3x3(int ligne, int colonne)
- {
- if (ligne < 1 || ligne >= Longueur - 1) return null;
- else if (colonne < 1 || colonne >= Largeur - 1) return null;
- else
- {
- MyPixel[,] MatExtraite = new MyPixel[3, 3];
- for (int i = 0; i < 3; i++)
- {
- for(int j = 0; j < 3; j++)
- {
- MatExtraite[i, j] = PixelTab[ligne - 1 + i, colonne - 1 + j];
- }
- }
- return MatExtraite;
- }
- }
- public void AppliquerUnFiltre (byte[,] convolution)
- {
- int decalage = convolution.GetLength(0) / 2; //Pour 3x3 decalage = 1
- int resultat;
- MyPixel[,] MatMultiplication = new MyPixel[convolution.GetLength(0), convolution.GetLength(1)];
- if (decalage == 1)
- {
- for (int i = decalage; i < Longueur - decalage; i++)
- {
- for (int j = decalage; j < Largeur - decalage; j++)
- {
- MyPixel[,] MatExtraite = ExtraireMatrice3x3(i, j);
- for (int ligne = 0; ligne < 3; ligne++)
- {
- for(int colonne = 0; colonne < 3; colonne++)
- {
- MatMultiplication[ligne, colonne] = MatExtraite[ligne, colonne] * convolution[ligne, colonne];
- resultat = resultat + MatMultiplication[ligne, colonne];
- }
- }
- PixelTab[i, j] = resultat;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement