Consider a sample image img as

enter image description here

If I apply a GradientFilter on it followed by a padding,

imggrad = GradientFilter[img,1];
gradpadded = ImagePad[imggrad,1];

Now I want to design a custom 3x3 max filter to detect the edges. The plan is to place the filter at the top left corner of the gradpadded(at the position (1,1)) and apply the filter on the first 3x3 image data. Next, I wish to find the position of the maximum value within the selected data. After that, the filter will be centered at that corresponding maximum value position and will be applied on the corresponding image portion. This process will carry on until the filter reaches the end of the image or returns back to an earlier position and thus completing a loop.

How can I do this?

  • $\begingroup$ Take a look at ImageConvolve and at MaxFilter...Moreover, it seems you already know how to do it. I mean, you know how to devise the kernel of the max filter you need. Just read the functions cited, particularly the first one... $\endgroup$ Commented Feb 19, 2018 at 19:29
  • $\begingroup$ You should probably start by reading the image processing tutorial in the documentation. Then browse the list of image processing functions, and you should be able to do most of these things. If not, come back and revise this question. As it is, it's way too broad IMO $\endgroup$ Commented Feb 19, 2018 at 19:32

1 Answer 1


It could be a starting point by using MaxFilter of different sizes:

ImageAssemble[ImageSubtract[MaxFilter[img, #], img] & /@ Table[{i, i}, {i, 3}]]

enter image description here


Your Answer

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

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