# Should Edge Detection Be Applied in Spatial or in Frequency Domain?

I want to ask why everywhere is used to do edge detection in spatial domain and not in frequency domain with FFT of image and apply HP filter. Thank you.

We need to separate the concept of edge detection from the tools we use to apply the procedure.

Edges are local property of the image. Being so local means we don't analyze the image in frequency domain but in spatial domain.
Yet, a common step for edge detection is applying High Pass / Gradient Filter. Since those are Linear Shift Invariant operators we may apply them according to the Convolution Theorem.

Classic edge detection procedure can be built according to Canny Edge Detector (See Why Is the Canny Edge Detection Used Instead of Sobel / Prewitt Edge Detection Before Hough Transformation):

1. Apply Low Pass Filter (Usually Gaussian Blur).
This can be applied in Frequency Domain though it may be faster do in spatial domain.
2. Apply Gradient (High Pass Filter) / Edge Detector Filter.
Usually Roberts, Prewitt or Sobel. Also can be applied in frequency domain. A more optimal filter, in my opinion, would be applying the 1st Derivative of Gaussian Filter. Then we can, in one step, apply both the HPF and the LPF (Hence Band Pass Filter).
3. Extract Magnitude and Direction of Potential Edges.
Simple analysis of the 2 images of the output of the previous filter. Basically a feature extraction for the next steps.
4. Thresholding.
We keep only potential edges where their magnitude was large enough (Above a threshold we set).
5. Edge Tracking and Hysteresis.
We use the direction knowledge to go along edges and combine long edges even in the case some parts of it have a magnitude lower than the threshold.

The above is a scheme for a very effective edge detector. Of course we don't implement it manually but use libraries which implemented this and tweaked the implementation.
You may find it in MATLAB's edge() (Under the canny method), OpenCV's cv::Canny and Python SciKit - Image's feature.canny().

As you may see, while some phases of the procedure can be applied in frequency domain, conceptually, edge detection is a process done in spatial domain on local features.

Regarding speed, where to apply what. Have a look at Strategy / Method for Implementation of the Fastest 1D Linear Convolution / Correlation. Though the answer is for 1D it applies for 2D as well. In most cases, since the kernels used above are very small, applying the whole process in spatial domain will be faster. It might be different if you apply the same kernel to many images at once.

• “applying the 1st Derivative of Gaussian Filter.” This is indeed what the original Canny paper proposes. In popular culture it somehow got split into your steps 1 and 2, not sure why. Maybe because of what filters are available in OpenCV? May 20, 2022 at 23:58
• @CrisLuengo, I am not sure when it happened. Not string in history of it (Maybe because I'm relatively new?). You made me learn a fact :-).
– Royi
May 21, 2022 at 6:20

What you claim is simply not true. One step in edge detection is often a simple high-pass (or band-pass) filter, and those are commonly applied using fast convolution, which is a frequency-domain algorithm.

• Then why is everywhere in edge detection posted info about Sobel operator, Perwitt and etc? Is it easier to do it in spatial domain with convolution or what ? I cant find obvious reason to do edge detection only in spatial domain.
– Olo
Dec 8, 2020 at 19:53
• It's easy to explain. It's not easier to do, necessary. For some things it is. For everything nonlinear, it's usually necessary. Dec 8, 2020 at 19:54
• So for linear transformation it is necessary to do it in spatial domain? and in nonlinear it can be done in both (freq and spatial)? Thx for ans u helped me so much
– Olo
Dec 8, 2020 at 19:57
• No, exactly the other way around. If something is linear, and you're using a linear transform like the Fourier transform, it can be done in whichever domain is easier/faster/elegant. Non-linear operations don't "translate". Dec 8, 2020 at 20:02
• @MarcusMüller, Since the kernels of Edge Detectors filters are so small an optimized implementation in spatial domain will be faster. So calling DFT Based Convolution Fast Convolution isn't accurate in this case (Also I don't think this is a good term at all).
– Royi
Sep 5, 2021 at 3:25