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

Parallel Pixel Maps #602

Merged
merged 17 commits into from
May 26, 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
6 changes: 3 additions & 3 deletions examples/color_effects.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Demonstrates adding a color tint and applying a color gradient to a grayscale image.

use image::{open, Luma, Rgb};
use imageproc::map::map_colors;
use imageproc::map::map_pixels;
use imageproc::pixelops::weighted_sum;
use std::env;
use std::path::Path;
Expand Down Expand Up @@ -44,13 +44,13 @@ fn main() {
let blue = Rgb([0u8, 0u8, 255u8]);

// Apply the color tint to every pixel in the grayscale image, producing a image::RgbImage
let tinted = map_colors(&image, |pix| tint(pix, blue));
let tinted = map_pixels(&image, |pix| tint(pix, blue));
tinted.save(path.with_file_name("tinted.png")).unwrap();

// Apply color gradient to each image pixel
let black = Rgb([0u8, 0u8, 0u8]);
let red = Rgb([255u8, 0u8, 0u8]);
let yellow = Rgb([255u8, 255u8, 0u8]);
let gradient = map_colors(&image, |pix| color_gradient(pix, black, red, yellow));
let gradient = map_pixels(&image, |pix| color_gradient(pix, black, red, yellow));
gradient.save(path.with_file_name("gradient.png")).unwrap();
}
4 changes: 2 additions & 2 deletions examples/hough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use image::{open, Rgb};
use imageproc::edges::canny;
use imageproc::hough::{detect_lines, draw_polar_lines, LineDetectionOptions, PolarLine};
use imageproc::map::map_colors;
use imageproc::map::map_pixels;
use std::env;
use std::fs;
use std::path::Path;
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main() {
let black = Rgb::<u8>([0, 0, 0]);

// Convert edge image to colour
let color_edges = map_colors(&edges, |p| if p[0] > 0 { white } else { black });
let color_edges = map_pixels(&edges, |p| if p[0] > 0 { white } else { black });

// Draw lines on top of edge image
let lines_image = draw_polar_lines(&color_edges, &lines, green);
Expand Down
6 changes: 3 additions & 3 deletions examples/seam_carving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use image::{open, GrayImage, Luma, Pixel};
use imageproc::definitions::Clamp;
use imageproc::gradients::gradients;
use imageproc::kernel;
use imageproc::map::map_colors;
use imageproc::map::map_pixels;
use imageproc::seam_carving::*;
use std::env;
use std::fs;
Expand Down Expand Up @@ -54,7 +54,7 @@ fn main() {
}

// Draw the seams on the original image.
let gray_image = map_colors(&input_image, |p| p.to_luma());
let gray_image = map_pixels(&input_image, |p| p.to_luma());
let annotated = draw_vertical_seams(&gray_image, &seams);
let annotated_path = output_dir.join("annotated.png");
annotated.save(&annotated_path).unwrap();
Expand All @@ -69,7 +69,7 @@ fn main() {
Luma([mean as u32])
},
);
let clamped_gradients: GrayImage = map_colors(&gradients, |p| Luma([Clamp::clamp(p[0])]));
let clamped_gradients: GrayImage = map_pixels(&gradients, |p| Luma([Clamp::clamp(p[0])]));
let annotated_gradients = draw_vertical_seams(&clamped_gradients, &seams);
let gradients_path = output_dir.join("gradients.png");
clamped_gradients.save(&gradients_path).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/template_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use image::{open, GenericImage, GrayImage, Luma, Rgb, RgbImage};
use imageproc::definitions::Image;
use imageproc::drawing::draw_hollow_rect_mut;
use imageproc::map::map_colors;
use imageproc::map::map_pixels;
use imageproc::rect::Rect;
#[cfg(feature = "rayon")]
use imageproc::template_matching::match_template_parallel;
Expand Down Expand Up @@ -72,7 +72,7 @@ fn convert_to_gray_image(image: &Image<Luma<f32>>) -> GrayImage {

let range = hi - lo;
let scale = |x| (255.0 * (x - lo) / range) as u8;
map_colors(image, |p| Luma([scale(p[0])]))
map_pixels(image, |p| Luma([scale(p[0])]))
}

fn copy_sub_image(image: &GrayImage, x: u32, y: u32, w: u32, h: u32) -> GrayImage {
Expand All @@ -92,7 +92,7 @@ fn copy_sub_image(image: &GrayImage, x: u32, y: u32, w: u32, h: u32) -> GrayImag
}

fn draw_green_rect(image: &GrayImage, rect: Rect) -> RgbImage {
let mut color_image = map_colors(image, |p| Rgb([p[0], p[0], p[0]]));
let mut color_image = map_pixels(image, |p| Rgb([p[0], p[0], p[0]]));
draw_hollow_rect_mut(&mut color_image, rect, Rgb([0, 255, 0]));
color_image
}
Expand Down
4 changes: 2 additions & 2 deletions src/filter/sharpen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{filter_clamped, gaussian_blur_f32};
use crate::{
definitions::{Clamp, Image},
kernel::Kernel,
map::{map_colors2, map_subpixels},
map::{map_pixels2, map_subpixels},
};
use image::{GrayImage, Luma};

Expand All @@ -22,7 +22,7 @@ pub fn sharpen3x3(image: &GrayImage) -> GrayImage {
pub fn sharpen_gaussian(image: &GrayImage, sigma: f32, amount: f32) -> GrayImage {
let image = map_subpixels(image, |x| x as f32);
let smooth: Image<Luma<f32>> = gaussian_blur_f32(&image, sigma);
map_colors2(&image, &smooth, |p, q| {
map_pixels2(&image, &smooth, |p, q| {
let v = (1.0 + amount) * p[0] - amount * q[0];
Luma([<u8 as Clamp<f32>>::clamp(v)])
})
Expand Down
Loading
Loading