A C++ implementation of the Laplacian edge detection filter compiled as a shared library and wrapped with Python ctypes for easy integration.
.
├── laplacian.cpp # C source with Laplacian filter implementation
├── liblaplacian.dylib # Compiled shared library (macOS)
├── laplacian_wrapper.py # Python wrapper using ctypes
└── image-ex.jpg # Example image for testing
-
C++ Core (
laplacian.cpp)- Implements the Laplacian kernel: 3x3 convolution matrix
- Processes grayscale image data as flat array
- Returns filtered image with edge detection applied
- Compiled as shared library for cross-language usage
-
Python Wrapper (
laplacian_wrapper.py)- Loads the compiled C++ library using ctypes
- Converts PIL images to numpy arrays
- Calls C++ filter function with image data
- Returns results as numpy arrays for matplotlib visualization
-
Data Flow
Image File (JPG) → PIL Load → Grayscale Convert → NumPy Array → C++ Filter via ctypes → Filtered NumPy Array → Matplotlib Display
- Python 3.6+
- NumPy
- Pillow
- Matplotlib
from laplacian_wrapper import laplacian, show
# Get filtered image
original, filtered = laplacian('image-ex.jpg')
# Display side by side
show('image-ex.jpg')g++ -shared -fPIC -o liblaplacian.dylib laplacian.cpp -std=c++11