Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Improvements #620

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading