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

How to draw lines with different width? #513

Open
SunDoge opened this issue Jan 5, 2023 · 2 comments
Open

How to draw lines with different width? #513

SunDoge opened this issue Jan 5, 2023 · 2 comments

Comments

@SunDoge
Copy link

SunDoge commented Jan 5, 2023

For example the thickness in opencv and linewidth in matplotlib.

@willhansen
Copy link

Doesn't look like it's implemented (really should be though).

Possible workarounds include:

  • A bunch of parallel line segments really close together
  • A polygon

https://docs.rs/imageproc/latest/imageproc/drawing/fn.draw_polygon.html
https://docs.rs/imageproc/latest/imageproc/drawing/fn.draw_line_segment.html
https://docs.rs/imageproc/latest/imageproc/drawing/fn.draw_antialiased_line_segment.html

@SamyAB
Copy link

SamyAB commented Jan 28, 2024

I agree that it is something that I would expect from a shape drawing function. It is an option in most tools, programmatic or GUIs.

I could try submitting a PR for it, but what would be the API? Would it be adding new functions suffixed by _with_thickness, or adding a parameter to the currently available functions (i.e. a breaking change)?

What about the offset of the thickness, should it always be a on a single side of the shape? If yes which side? Should it be on both side? If yes what side should thicker when the thickness is an odd number?

Assuming the addition of new functions suffixed by _with_thickness, with a one sided offset, a naive implementation for the hollow rectangle would look something like this

fn draw_hollow_rect_with_thichness<I>(
    image: &I,
    rect: Rect,
    color: I::Pixel,
    thickness: u16,
) -> Image<I::Pixel>
where
    I: GenericImage,
{
    let rect_x = rect.left();
    let rect_y = rect.top();
    let rect_width = rect.width();
    let rect_height = rect.height();
    let mut image_with_rectangle = drawing::draw_hollow_rect(image, rect, color);

    for offset in 0..thickness {
        let thickness_rect = Rect::at(rect_x - i32::from(offset), rect_y - i32::from(offset))
            .of_size(
                rect_width + 2 * u32::from(offset),
                rect_height + 2 * u32::from(offset),
            );
        drawing::draw_hollow_rect_mut(&mut image_with_rectangle, thickness_rect, color);
    }

    image_with_rectangle
}

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants