This application demonstrates real-time contour smoothing using Fourier descriptors with an interactive GUI built with Tkinter and Matplotlib.
The application transforms contours of binary images into the frequency domain using Fast Fourier Transform (FFT) and allows interactive filtering of the frequency components. By adjusting the number of Fourier descriptors retained, users can control the smoothness of the contour in real-time.
- Interactive GUI with real-time visualization
- Side-by-side display of original and smoothed contours
- Mouse-controlled adjustment of smoothing level
- Fourier descriptor-based contour filtering
- The application loads an image and extracts the largest contour
- The contour is converted into a complex signal (x coordinates as real part, y coordinates as imaginary part)
- Fast Fourier Transform (FFT) is applied to the complex contour
- User interactively controls how many descriptors to retain
- Inverse FFT is applied to reconstruct the smoothed contour
- Both original and smoothed contours are displayed in real-time
Fourier descriptors are powerful tools for shape analysis and representation. The main steps are:
- Contour Representation: Convert contour points to complex numbers:
z(t) = x(t) + j*y(t)
- Fourier Transform: Apply FFT to get frequency components:
Z(k) = FFT(z(t))
- Filtering: Retain only the first N descriptors (low-frequency components)
- Reconstruction: Apply inverse FFT to get smoothed contour:
z'(t) = IFFT(Z'(k))
- Python 3.x
- OpenCV
- NumPy
- Matplotlib
- Tkinter
pip install opencv-python numpy matplotlib
- Update the
image_path
variable in the code to point to your binary image - Run the script:
python contour_smoothing.py
- Move your mouse horizontally across the plot to adjust the number of Fourier descriptors
- The left plot shows the original contour, while the right plot displays the smoothed version
- Shape analysis and recognition
- Noise removal from contours
- Feature extraction in computer vision
- Educational tool for understanding Fourier transforms in image processing
MIT
@bemoregt