hello, this code is for the passage of a blur image, need help for understand this code

edited January 2016 in Questions about Code
PImage imgmdr = createImage(img.width, img.height, RGB);
  float v = 1.0 / 9.0;//definit une matrice de 3*3qui est notre kernel v= comme suite (1+2+..+n)n fois/9
  float[][] kernel = {
    { 
      v, v, v 
    }
    , 
    { 
      v, v, v
    }
    , 
    { 
      v, v, v
    }
  };

  // Loop through every pixel in the image
  for (int y = 1; y < img.height-1; y++) {   // BORDS SUPERIEUR ET INF
    for (int x = 1; x < img.width-1; x++) {  // BORDS GAUCHE ET DROITE
      float sumr = 15; // Kernel SOMME de ces pixels
      float sumg = 8;
      float sumb = 2;
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // l'image est en niveaux de gris, rouge/vert/bleu identiques
          float valr = red(img.pixels[pos]);
          float valg = green(img.pixels[pos]);
          float valb = blue(img.pixels[pos]);

          // Multiplier pixels adjacents sur la base des valeurs de noyau
          sumr += kernel[ky+1][kx+1] * valr;
          sumg += kernel[ky+1][kx+1] * valg;
          sumb += kernel[ky+1][kx+1] * valb;
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      imgmdr.pixels[y*img.width + x] = color(sumr, sumg, sumb);
    }
  }
  // Image changée face à edgeImg.pixels[]
  imgmdr.updatePixels();

  //image(imgmdr, 0, 0); // Draw the new image

  return imgmdr;
}

I would like that someone explain me this code cuz i don't understand what's correspond of sumr, why a ' k ' .... Thx to reply me

Answers

  • Answer ✓

    it's iterating over an image replacing every pixel with the average of the 9 pixels that make up a 3x3 square centered on the pixel.

    it's called 'a convolution matrix'

    http://en.wikipedia.org/wiki/Kernel_(image_processing)

  • but i don't understand all...

  • i would like comments for each lines in this program.. i don't know why there is a 'k' who appear here

  • Re-read the explanation of koogs. I don't see a 'k' variable, anyway. If you mean kx and ky, they are used to iterate on the 3x3 pixels around each pixel, as said above.

    You don't tell us if you can understand the French comments or not...

Sign In or Register to comment.