How do those matrices work? Do I need to multiple every single pixel? How about the upperleft, upperright, bottomleft and bottomleft pixels where there's no surrounding pixel? And does the matrix work from left to right and from up to bottom or from up to bottom first and then left to right?

Why does this kernel (Edge enhance):

this kernel (Edge enhance)

turns into this image:

this image



1 Answer 1


The convolution process works by multiplying every single pixel on the image with the matrix/kernel. And for the outer pixel in top, bottom, right and left there are several ways to do it:

  1. You can ignore it, so you can start from the second line if the kernel is 3x3.
  2. You can put a 0 value as the outer border.
  3. You can copy the closest neighbor pixel value in as the outer border.
  4. You can pretend the image is circular by using the opposite pixel. Top with bottom and left with right border.

As far as I know the matrix goes from left to right direction. And for that matrix (the edge enhancement), it gets pixel that have huge difference with the left neighbor. The pixel is multiplied with 1 and the left neighbor is multiplied with -1. If the two pixels have huge difference, the result will be near to white (1 or 255) but if the two pixels have small difference, the result will be near black (0).

I hope this answers your questions.

  • $\begingroup$ Why is white 1 or 255? And not just 255? So a big difference is for example -1*200+1*1=-199 and should be rounded to 0 = black? and a big difference is -1*1+1*200=199 and that should be rounded to 255=white? $\endgroup$ Mar 12, 2013 at 11:59
  • $\begingroup$ @user1095332 the pixel value is 0 to 255 for 8-bit gray-scale image, even if the black and white image. for binary image, black is 0 and white is 1. But when it's represented in an digital image, the pixel value is 0 for black and 255 for white. The negative value (-199) needs to be changed to 0, and so does the value more than 255 have to be changed to 255. But the value between 0 and 255 is accepted. It will give gray color. The pixel will show lighter if the value near 255, and darker when the value close to 0. $\endgroup$
    – nsrjws
    Mar 12, 2013 at 12:50
  • $\begingroup$ Thank you! I understand it a bit better, but 1. it still doesn't feel obvious when I do the calculations for all the matrices, how can I understand the matrices sharpen, edge detect and emboss better for example and make them feel more intuitive? And 2. which books would you understand the math used in image processing? $\endgroup$ Mar 12, 2013 at 16:32
  • $\begingroup$ @user1095332 I also find it difficult to understand the effect of some convolution matrix. I usually just try to use the matrix with an image and see the result to understand the effect. The book for Image Processing that I get from My campus is 'Digital Image Processing' by Gonzalez and Woods. I think that book explain the image processing more mathematically. I hope that can help you. $\endgroup$
    – nsrjws
    Mar 12, 2013 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.