Feature: Add median filter option to blur node
This PR adds a new dedicated median filter node to the Raster: Filter category, providing users with an effective tool for noise reduction while preserving edges.
Changes Made
- Added new
median_filternode function with its own dedicated interface - Implemented
median_filter_algorithm()function that processes each color channel independently - Added
median_quickselect()helper function usingselect_nth_unstable_by()withtotal_cmp()for safe NaN handling - Uses O(n) quickselect algorithm instead of O(n log n) full sorting for better performance
Why a Separate Node?
Median filtering serves a fundamentally different purpose than blur operations:
- Primary use case: Noise reduction (especially salt-and-pepper noise) while preserving sharp edges
- Different behavior: Does not create smooth blur effects like Gaussian/box blur
- Distinct parameters: Optimal radius ranges and use cases differ from blur filters
- UI clarity: Users can easily distinguish between blur effects and noise reduction
Use Cases
- Removing salt-and-pepper noise from scanned images
- Cleaning up digital photography noise without edge destruction
- Pre-processing images before applying other effects
- Situations where traditional blur would be too destructive to image details
Technical Implementation
- Uses quickselect algorithm (O(n) average case) for efficient median calculation
- Operates on square neighborhoods defined by radius parameter
- Processes RGBA channels independently to maintain color fidelity
- Safe NaN handling with
f32::total_cmp()to prevent runtime panics - Consistent gamma space processing with existing filter nodes
The implementation follows established patterns from other filter nodes with proper error handling and performance optimization.
Closes feature in Issue No. #912
Please make this a separate node.
Please make this a separate node.
@Keavon Could you explain more? What do you mean by that?
You mean separating the node for the median filter functionality instead of adding it as an option to the existing blur node?
You mean separating the node for the median filter functionality instead of adding it as an option to the existing blur node?
Yes
@Keavon Could you review it?
!build
| 📦 Build Complete for a6b538ad1df037ff77800c01425b1dad9340cc2b |
|---|
| https://fb96ac02.graphite.pages.dev |
@Keavon , any updates?
!build
| 📦 Build Complete for d19c7ff074f0fc17b9a0584083d0645edba1424b |
|---|
| https://b98c1796.graphite.pages.dev |