Pure Rust Implementation of the Butterworth Filter
Try the interactive Butterworth filter demo directly in your browser, built with WebAssembly:
➡️ Live Demo Link ⬅️
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.
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");
}