Skip to content

Commit

Permalink
Fix some warnings (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Lauzier committed Feb 19, 2022
1 parent 078cf87 commit f8af4a2
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/color_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() {
// Load a image::DynamicImage and convert it to a image::GrayImage
let image = open(path)
.expect(&format!("Could not load image at {:?}", path))
.to_luma();
.to_luma8();

let blue = Rgb([0u8, 0u8, 255u8]);

Expand Down
2 changes: 1 addition & 1 deletion examples/display_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {

let image = image::open(&image_path)
.expect("No image found at provided path")
.to_rgba();
.to_rgba8();

display_image("", &image, 500, 500);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/display_multiple_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ fn main() {

let first_image = image::open(&first_image_path)
.expect("No image found at provided path")
.to_rgba();
.to_rgba8();
let second_image = image::open(&second_image_path)
.expect("No image found at provided path")
.to_rgba();
.to_rgba8();

display_multiple_images("", &vec![&first_image, &second_image], 500, 500);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gradients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() {
// Load image and convert to grayscale
let input_image = open(input_path)
.expect(&format!("Could not load image at {:?}", input_path))
.to_luma();
.to_luma8();

// Save grayscale image in output directory
let gray_path = output_dir.join("grey.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn create_hog_image(input: &Path, signed: bool) {
// Load a image::DynamicImage and convert it to a image::GrayImage
let image = open(input)
.expect(&format!("Could not load image at {:?}", input))
.to_luma();
.to_luma8();

// We're not going to do anything interesting with the block sizes here - they're
// only relevant when combining and normalising per-cell histograms, and in this
Expand Down
2 changes: 1 addition & 1 deletion examples/hough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
// Load image and convert to grayscale
let input_image = open(input_path)
.expect(&format!("Could not load image at {:?}", input_path))
.to_luma();
.to_luma8();

// Save grayscale image in output directory
let gray_path = output_dir.join("grey.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() -> ImageResult<()> {

let image = open(input_path)
.expect(&format!("Could not load image at {:?}", input_path))
.to_rgb();
.to_rgb8();

let translate = Projection::translate(90.0, 10.0);
warp(
Expand Down
2 changes: 1 addition & 1 deletion examples/seam_carving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
// Load image and convert to grayscale
let input_image = open(input_path)
.expect(&format!("Could not load image at {:?}", input_path))
.to_rgb();
.to_rgb8();

// Save original image in output directory
let original_path = output_dir.join("original.png");
Expand Down
2 changes: 1 addition & 1 deletion examples/template_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn main() {
// Load image and convert to grayscale
let image = open(input_path)
.expect(&format!("Could not load image at {:?}", input_path))
.to_luma();
.to_luma8();

// Extract the requested image sub-region to use as the template
let template = copy_sub_image(
Expand Down
2 changes: 1 addition & 1 deletion src/drawing/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
y_min = max(0, min(y_min, height as i32 - 1));
y_max = max(0, min(y_max, height as i32 - 1));

let mut closed: Vec<Point<i32>> = poly.iter().copied().collect();
let mut closed: Vec<Point<i32>> = poly.to_vec();
closed.push(poly[0]);

let edges: Vec<&[Point<i32>]> = closed.windows(2).collect();
Expand Down
8 changes: 4 additions & 4 deletions src/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ fn non_maximum_suppression(
angle += 180.0
}
// Clamp angle.
let clamped_angle = if angle >= 157.5 || angle < 22.5 {
let clamped_angle = if !(22.5..157.5).contains(&angle) {
0
} else if angle >= 22.5 && angle < 67.5 {
} else if (22.5..67.5).contains(&angle) {
45
} else if angle >= 67.5 && angle < 112.5 {
} else if (67.5..112.5).contains(&angle) {
90
} else if angle >= 112.5 && angle < 157.5 {
} else if (112.5..157.5).contains(&angle) {
135
} else {
unreachable!()
Expand Down
12 changes: 6 additions & 6 deletions src/filter/median.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ where
let rx = x_radius as i32;
let ry = y_radius as i32;

let mut hist = initialise_histogram_for_top_left_pixel(&image, x_radius, y_radius);
slide_down_column(&mut hist, &image, &mut out, 0, rx, ry);
let mut hist = initialise_histogram_for_top_left_pixel(image, x_radius, y_radius);
slide_down_column(&mut hist, image, &mut out, 0, rx, ry);

for x in 1..width {
if x % 2 == 0 {
slide_right(&mut hist, &image, x, 0, rx, ry);
slide_down_column(&mut hist, &image, &mut out, x, rx, ry);
slide_right(&mut hist, image, x, 0, rx, ry);
slide_down_column(&mut hist, image, &mut out, x, rx, ry);
} else {
slide_right(&mut hist, &image, x, height - 1, rx, ry);
slide_up_column(&mut hist, &image, &mut out, x, rx, ry);
slide_right(&mut hist, image, x, height - 1, rx, ry);
slide_up_column(&mut hist, image, &mut out, x, rx, ry);
}
}
out
Expand Down
4 changes: 2 additions & 2 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn bilateral_filter(
) -> Image<Luma<u8>> {
/// Un-normalized Gaussian weights for look-up tables.
fn gaussian_weight(x: f32, sigma_squared: f32) -> f32 {
return (-0.5 * x.powi(2) / sigma_squared).exp();
(-0.5 * x.powi(2) / sigma_squared).exp()
}

/// Effectively a meshgrid command with flattened outputs.
Expand All @@ -79,7 +79,7 @@ pub fn bilateral_filter(
for i in window_range {
rr.append(&mut vec![i; (window_size + 1) as usize]);
}
return (rr, cc);
(rr, cc)
}

/// Create look-up table of Gaussian weights for color dimension.
Expand Down
2 changes: 1 addition & 1 deletion src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn min_area_rect<T>(points: &[Point<T>]) -> [Point<T>; 4]
where
T: NumCast + Copy + Ord,
{
let hull = convex_hull(&points);
let hull = convex_hull(points);
match hull.len() {
0 => panic!("no points are defined"),
1 => [hull[0]; 4],
Expand Down
4 changes: 2 additions & 2 deletions src/hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ fn hog_descriptor_from_hist_grid(grid: View3d<'_, f32>, spec: HogSpec) -> Vec<f3

for by in 0..spec.blocks_high {
for bx in 0..spec.blocks_wide {
let mut block_data = block_view.inner_slice_mut(bx, by);
let mut block = View3d::from_raw(&mut block_data, spec.block_internal_lengths());
let block_data = block_view.inner_slice_mut(bx, by);
let mut block = View3d::from_raw(block_data, spec.block_internal_lengths());

for iy in 0..spec.options.block_side {
let cy = by * spec.options.block_stride + iy;
Expand Down
2 changes: 1 addition & 1 deletion src/seam_carving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
"Cannot find seams if image width is < 2"
);

let mut gradients = sobel_gradient_map(&image, |p| {
let mut gradients = sobel_gradient_map(image, |p| {
let gradient_sum: u16 = p.channels().iter().sum();
let gradient_mean: u16 = gradient_sum / P::CHANNEL_COUNT as u16;
Luma([gradient_mean as u32])
Expand Down
2 changes: 1 addition & 1 deletion src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
pub fn percentile(image: &GrayImage, p: u8) -> u8 {
assert!(p <= 100, "requested percentile must be <= 100");

let cum_hist = cumulative_histogram(&image).channels[0];
let cum_hist = cumulative_histogram(image).channels[0];
let total = cum_hist[255] as u64;

for i in 0..256 {
Expand Down
4 changes: 2 additions & 2 deletions src/template_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ pub fn match_template(
MatchTemplateMethod::SumOfSquaredErrorsNormalized
| MatchTemplateMethod::CrossCorrelationNormalized };
let image_squared_integral = if should_normalize {
Some(integral_squared_image(&image))
Some(integral_squared_image(image))
} else {
None
};
let template_squared_sum = if should_normalize {
Some(sum_squares(&template))
Some(sum_squares(template))
} else {
None
};
Expand Down
2 changes: 1 addition & 1 deletion src/union_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl DisjointSetForest {
/// Constructs forest of singletons with count elements.
pub fn new(count: usize) -> DisjointSetForest {
let parent: Vec<usize> = (0..count).collect();
let tree_size = vec![1 as usize; count];
let tree_size = vec![1_usize; count];
DisjointSetForest {
count,
parent,
Expand Down
8 changes: 4 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ where
let mut err = "pixels do not match.\n".to_owned();

// Find the boundaries of the region containing diffs
let top_left = diffs.iter().fold((u32::MAX, u32::MAX), |acc, ref d| {
let top_left = diffs.iter().fold((u32::MAX, u32::MAX), |acc, d| {
(acc.0.min(d.x), acc.1.min(d.y))
});
let bottom_right = diffs
.iter()
.fold((0, 0), |acc, ref d| (acc.0.max(d.x), acc.1.max(d.y)));
.fold((0, 0), |acc, d| (acc.0.max(d.x), acc.1.max(d.y)));

// If all the diffs are contained in a small region of the image then render all of this
// region, with a small margin.
Expand All @@ -506,7 +506,7 @@ where

let diff_locations = diffs.iter().map(|d| (d.x, d.y)).collect::<HashSet<_>>();

err.push_str(&colored(&"Actual:", Color::Red));
err.push_str(&colored("Actual:", Color::Red));
let actual_rendered = render_image_region(actual, left, top, right, bottom, |x, y| {
if diff_locations.contains(&(x, y)) {
Color::Red
Expand All @@ -516,7 +516,7 @@ where
});
err.push_str(&actual_rendered);

err.push_str(&colored(&"Expected:", Color::Green));
err.push_str(&colored("Expected:", Color::Green));
let expected_rendered = render_image_region(expected, left, top, right, bottom, |x, y| {
if diff_locations.contains(&(x, y)) {
Color::Green
Expand Down
8 changes: 4 additions & 4 deletions tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ trait FromDynamic {

impl FromDynamic for GrayImage {
fn from_dynamic(image: &DynamicImage) -> Self {
image.to_luma()
image.to_luma8()
}
}

impl FromDynamic for RgbImage {
fn from_dynamic(image: &DynamicImage) -> Self {
image.to_rgb()
image.to_rgb8()
}
}

impl FromDynamic for RgbaImage {
fn from_dynamic(image: &DynamicImage) -> Self {
image.to_rgba()
image.to_rgba8()
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ fn test_sharpen_gaussian() {
#[test]
fn test_match_histograms() {
fn match_to_zebra_histogram(image: &GrayImage) -> GrayImage {
let zebra = load_image_or_panic(Path::new(INPUT_DIR).join("zebra.png")).to_luma();
let zebra = load_image_or_panic(Path::new(INPUT_DIR).join("zebra.png")).to_luma8();
imageproc::contrast::match_histogram(image, &zebra)
}
compare_to_truth(
Expand Down

0 comments on commit f8af4a2

Please sign in to comment.