Skip to content

Commit 204b26b

Browse files
committed
Docs updated
1 parent 5aa6277 commit 204b26b

6 files changed

Lines changed: 23 additions & 15 deletions

File tree

src/filter/bilateral.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ where
6262
/// define how different two pixels are based on their colors. Common examples may include simple
6363
/// absolute difference for greyscale pixels or cartesian distance in the CIE-Lab color space
6464
/// \[1\].
65+
/// * `extend` - Enum specifying how to sample pixels outside of image boundaries.
6566
///
6667
/// This filter averages pixels based on their spatial distance as well as their color
6768
/// distance. Spatial distance is measured by the Gaussian function of the Euclidean distance

src/filter/box_filter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use crate::integral_image::{column_running_sum, row_running_sum};
99
/// sum to one. i.e. each output pixel is the unweighted mean of
1010
/// a rectangular region surrounding its corresponding input pixel.
1111
/// We handle locations where the kernel would extend past the image's
12-
/// boundary by treating the image as if its boundary pixels were
13-
/// repeated indefinitely.
12+
/// boundary according to `extend`.
1413
// TODO: for small kernels we probably want to do the convolution
1514
// TODO: directly instead of using an integral image.
1615
// TODO: more formats!

src/filter/median.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use image::Pixel;
55
/// Applies a median filter of given dimensions to an image. Each output pixel is the median
66
/// of the pixels in a `(2 * x_radius + 1) * (2 * y_radius + 1)` kernel of pixels in the input image.
77
///
8-
/// Pads by continuity. Performs O(max(x_radius, y_radius)) operations per pixel.
8+
/// Sampling outside of image boundaries is controlled by `extend`.
9+
/// Performs O(max(x_radius, y_radius)) operations per pixel.
910
///
1011
/// # Examples
1112
/// ```
@@ -34,14 +35,17 @@ use image::Pixel;
3435
/// // 9 | 9 100 11 | 11
3536
/// // -----------------
3637
/// // 9 9 100 11 11
38+
/// //
39+
/// // Here we choose `Border<P>` corresponding to it:
40+
/// let extend = Border::Replicate;
3741
///
3842
/// let filtered = gray_image!(
3943
/// 2, 3, 3;
4044
/// 9, 7, 7;
4145
/// 9, 11, 11
4246
/// );
4347
///
44-
/// assert_pixels_eq!(median_filter(&image, 1, 1, Border::Replicate), filtered);
48+
/// assert_pixels_eq!(median_filter(&image, 1, 1, extend), filtered);
4549
/// # }
4650
/// ```
4751
///
@@ -323,7 +327,7 @@ impl HistSet {
323327
}
324328
}
325329

326-
/// Safety: requires pixel.channels.len() <= self.data.len()
330+
/// Safety: requires P::CHANNEL_COUNT <= self.data.len()
327331
unsafe fn incr<P: Pixel<Subpixel = u8>>(&mut self, pixel: P) {
328332
let channels = pixel.channels();
329333
unsafe {
@@ -335,7 +339,7 @@ impl HistSet {
335339
}
336340
}
337341

338-
/// Safety: requires pixel.channels.len() <= self.data.len()
342+
/// Safety: requires P::CHANNEL_COUNT <= self.data.len()
339343
unsafe fn decr<P: Pixel<Subpixel = u8>>(&mut self, pixel: P) {
340344
let channels = pixel.channels();
341345
unsafe {
@@ -347,7 +351,7 @@ impl HistSet {
347351
}
348352
}
349353

350-
/// Safety: requires pixel.channels.len() <= self.data.len()
354+
/// Safety: requires P::CHANNEL_COUNT <= self.data.len()
351355
unsafe fn set_to_median<P: Pixel<Subpixel = u8>>(&self, pixel: &mut P) {
352356
let channels = pixel.channels_mut();
353357
unsafe {

src/filter/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use num::Num;
2222
use std::f32;
2323

2424
/// Returns 2d correlation of an image. Intermediate calculations are performed
25-
/// at type K, and the results converted to pixel Q via f. Pads by continuity.
25+
/// at type K, and the results converted to pixel Q via f.
26+
/// Sampling outside of image boundaries is controlled by `extend`.
2627
///
2728
/// # Panics
2829
/// If `P::CHANNEL_COUNT != Q::CHANNEL_COUNT`
@@ -186,7 +187,8 @@ where
186187
}
187188

188189
/// Returns 2d correlation of an image with a row-major kernel. Intermediate calculations are
189-
/// performed at type K, and the results clamped to subpixel type S. Pads by continuity.
190+
/// performed at type K, and the results clamped to subpixel type S.
191+
/// Sampling outside of image boundaries is controlled by `extend`.
190192
///
191193
/// A parallelized version of this function exists with [`filter_clamped_parallel`] when
192194
/// the crate `rayon` feature is enabled.
@@ -222,8 +224,8 @@ where
222224
}
223225

224226
/// Returns horizontal correlations between an image and a 1d kernel.
225-
/// Pads by continuity. Intermediate calculations are performed at
226-
/// type K.
227+
/// Sampling outside of image boundaries is controlled by `extend`.
228+
/// Intermediate calculations are performed at type K.
227229
#[must_use = "the function does not modify the original image"]
228230
pub fn horizontal_filter<P, K>(image: &Image<P>, kernel: &[K], extend: Border<P>) -> Image<P>
229231
where
@@ -250,8 +252,9 @@ where
250252
out
251253
}
252254

253-
/// Returns horizontal correlations between an image and a 1d kernel.
254-
/// Pads by continuity.
255+
/// Returns vertical correlations between an image and a 1d kernel.
256+
/// Sampling outside of image boundaries is controlled by `extend`.
257+
/// Intermediate calculations are performed at type K.
255258
#[must_use = "the function does not modify the original image"]
256259
pub fn vertical_filter<P, K>(image: &Image<P>, kernel: &[K], extend: Border<P>) -> Image<P>
257260
where

src/gradients.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub fn prewitt_gradients(image: &GrayImage, extend: Border<Luma<u8>>) -> Image<L
249249
/// [ 4, 0, 8], [ 8, 0, 8], [ 4, 0, 8]
250250
/// );
251251
///
252+
/// // Padding by continuity.
252253
/// let extend = Border::Replicate;
253254
///
254255
/// assert_pixels_eq!(

src/integral_image.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ pub fn variance(
317317
}
318318

319319
/// Computes the running sum of one row of image, padded
320-
/// at the beginning and end. The padding is by continuity.
320+
/// at the beginning and end. Padding method is controlled by `extend`.
321321
/// Takes a reference to buffer so that this can be reused
322322
/// for all rows in an image.
323323
///
@@ -388,7 +388,7 @@ pub fn row_running_sum(
388388
}
389389

390390
/// Computes the running sum of one column of image, padded
391-
/// at the top and bottom. The padding is by continuity.
391+
/// at the top and bottom. Padding method is controlled by `extend`.
392392
/// Takes a reference to buffer so that this can be reused
393393
/// for all columns in an image.
394394
///

0 commit comments

Comments
 (0)