Pure Rust Implementation of the Butterworth Filter
This crate provides a pure Rust implementation of the Butterworth filter, designed for high-performance spatial frequency filtering of images. It is inspired by and seeks to replicate the functionality of the Butterworth filter as implemented in the popular Python library, scikit-image.
The Butterworth filter offers a more robust method for applying spatial frequency filters to images compared to traditional FFT/IFFT-based methods. Filters with sharp cutoffs can often lead to the Gibbs phenomenon, where undesirable ringing artifacts appear near edges in the image. This issue is particularly problematic in applications such as EEG experiments (particularly low/mid visual ones that affect P100 amplitudes in the visual cortex) and other scenarios involving low-frequency signals. By providing a smoother transition between the passband and stopband, the Butterworth filter mitigates these effects, making it a preferred choice among vision scientists and image-processing experts.
- Pure Rust implementation for optimal performance and integration with Rust-based image processing pipelines.
- Support for both high-pass and low-pass filtering, with customizable cutoff frequency and filter order parameters.
- Detailed examples and documentation to help users quickly integrate the filter into their projects.
To visually demonstrate the effectiveness and similarity of our Rust implementation compared to the Python (scikit-image) version, here are comparison images. These comparisons help illustrate both the visual and frequency spectrum outcomes using identical input values across both implementations.
Here's a quick example of applying a high-pass Butterworth filter to an image:
cargo add butter2d
use image::{GrayImage, open};
use butter2d::butterworth;
fn main() {
let img = open("path/to/your/image.png").expect("Failed to open image").to_luma8();
let cutoff_frequency_ratio = 0.1;
let high_pass = true;
let order = 2.0;
let squared_butterworth = false;
let npad = 0;
let filtered_img = butterworth(
&img,
cutoff_frequency_ratio,
high_pass,
order,
squared_butterworth,
npad
);
filtered_img.save("path/to/save/filtered_image.png").expect("Failed to save filtered image");
}
For a hands-on experience, download the latest demo from Releases page. The demo, available for Windows, Mac, and Ubuntu, features interactive controls and dynamic image processing capabilities. As you adjust sliders, changes are applied in real-time, allowing for immediate visual feedback. This setup is specifically designed to facilitate the creation of fun scrambled versions of images dynamically. For instance, if you apply a high-pass filter and then a low-pass filter, the final output will be the low-pass version of the previously high-pass filtered image. For a more precise implementation, set your parameters first and then upload the image.
![Demo GIF](https://private-user-images.githubusercontent.com/54986652/324261149-ca53e795-bf83-4a92-af0a-ee82a47c9be5.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxOTI0NzYsIm5iZiI6MTcyNDE5MjE3NiwicGF0aCI6Ii81NDk4NjY1Mi8zMjQyNjExNDktY2E1M2U3OTUtYmY4My00YTkyLWFmMGEtZWU4MmE0N2M5YmU1LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIwVDIyMTYxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTZhN2FiYTAxZTRhZDE5NWRiODM3MTYzMzY3Y2JlNTAxMmZjMzNmYTk0NTYyZjE4ZDcyOGNiMjFlZDg2YTFjMzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.p2-maP4ZHEyciljvpvidkHnYR7JnT1viGlMKxLcWaPM)
Don't you like the WGPU version? You can also try my Tauri app For clearer and more precise implementations:
![App](https://private-user-images.githubusercontent.com/54986652/328676964-700ee080-c6d5-416c-8420-6f454867f84d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQxOTI0NzYsIm5iZiI6MTcyNDE5MjE3NiwicGF0aCI6Ii81NDk4NjY1Mi8zMjg2NzY5NjQtNzAwZWUwODAtYzZkNS00MTZjLTg0MjAtNmY0NTQ4NjdmODRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODIwVDIyMTYxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFkNTU3ZGQ5YTI0NzUzMmM0ZjRiNDZkYzAwYzU1NGYxNDhkZmVhM2VmOTI2NDc2ZmI5MjllZWE3Yzk3OTdiYjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TrG6MH3AoEH94C_h7ynuQMKnk5eMlVjcU7HSTI0nYa4)
Operating System | Package Type | Link |
---|---|---|
Windows | Installer | Download |
MSI Package | Download | |
macOS | DMG for Intel | Download |
DMG for Apple M1 | Download | |
Linux | Debian Package | Download |
AppImage | Download | |
Tarballs | macOS Intel | Download |
macOS Apple M1 | Download |