Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1.  public MyPixel[,] ExtraireMatrice3x3(int ligne, int colonne)
  2.         {
  3.             if (ligne < 1 || ligne >= Longueur - 1) return null;
  4.             else if (colonne < 1 || colonne >= Largeur - 1) return null;
  5.             else
  6.             {
  7.                 MyPixel[,] MatExtraite = new MyPixel[3, 3];
  8.                 for (int i = 0; i < 3; i++)
  9.                 {
  10.                     for(int j = 0; j < 3; j++)
  11.                     {
  12.                         MatExtraite[i, j] = PixelTab[ligne - 1 + i, colonne - 1 + j];
  13.                     }
  14.                 }
  15.                 return MatExtraite;
  16.             }
  17.         }
  18.  
  19.         public void AppliquerUnFiltre (byte[,] convolution)
  20.         {
  21.             int decalage = convolution.GetLength(0) / 2; //Pour 3x3 decalage = 1
  22.             int resultat;
  23.             MyPixel[,] MatMultiplication = new MyPixel[convolution.GetLength(0), convolution.GetLength(1)];
  24.             if (decalage == 1)
  25.             {
  26.                 for (int i = decalage; i < Longueur - decalage; i++)
  27.                 {
  28.                     for (int j = decalage; j < Largeur - decalage; j++)
  29.                     {
  30.                         MyPixel[,] MatExtraite = ExtraireMatrice3x3(i, j);
  31.                         for (int ligne = 0; ligne < 3; ligne++)
  32.                         {
  33.                             for(int colonne = 0; colonne < 3; colonne++)
  34.                             {
  35.                                 MatMultiplication[ligne, colonne] = MatExtraite[ligne, colonne] * convolution[ligne, colonne];
  36.                                 resultat = resultat + MatMultiplication[ligne, colonne];
  37.                             }
  38.                         }
  39.                         PixelTab[i, j] = resultat;
  40.                     }
  41.                 }
  42.             }
  43.            
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement