Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed May 19, 2024
1 parent 71ba4fd commit a262bb3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
9 changes: 1 addition & 8 deletions src/filter/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,8 @@ struct HistSet {

impl HistSet {
fn new(num_channels: u8, expected_count: u32) -> HistSet {
// Can't use vec![[0u32; 256], num_channels as usize]
// because arrays of length > 32 aren't cloneable.
let mut data = Vec::with_capacity(num_channels as usize);
for _ in 0..num_channels {
data.push([0u32; 256]);
}

HistSet {
data,
data: vec![[0u32; 256]; num_channels.into()],
expected_count,
}
}
Expand Down
32 changes: 29 additions & 3 deletions src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,40 @@ pub struct MinMax<T> {
}

/// Returns the minimum and maximum values per channel in an image.
///
/// # Panics
///
/// 1. If `image.is_empty()`
///
/// # Examples
///
/// ```
/// # extern crate image;
/// # #[macro_use]
/// # extern crate imageproc;
/// # fn main() {
/// use imageproc::stats::min_max;
///
/// let image = gray_image!(
/// 1, 2, 3;
/// 4, 5, 6);
///
/// // A greyscale image has only one channel.
/// let min_max = min_max(&image)[0];
///
/// assert_eq!(min_max.min, 1);
/// assert_eq!(min_max.max, 6);
/// # }
/// ````
pub fn min_max<P, T>(image: &Image<P>) -> Vec<MinMax<T>>
where
P: Pixel<Subpixel = T>,
T: Ord + Copy,
{
if image.is_empty() {
panic!("cannot find the range of an empty image");
}
assert!(
!image.is_empty(),
"cannot find the min_max() of an empty image"
);

let mut ranges = vec![(None, None); P::CHANNEL_COUNT as usize];

Expand Down

0 comments on commit a262bb3

Please sign in to comment.