GithubHelp home page GithubHelp logo

Comments (28)

ArtemGr avatar ArtemGr commented on August 18, 2024

And then maybe answer this question:
http://stackoverflow.com/questions/34440429/draw-a-line-in-a-bitmap-possibly-with-piston
; )

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

I added a simple Rust implementation of the Bresenham algorithm to the StackOverflow question: http://stackoverflow.com/a/34722500/284318

I'd be interested in giving this issue a stab. @theotherphil can you give me some starting point on where in the library I'd add something like that, and what stucts the function would operate on? Or in other words, what should the API look like?

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

Also, drawing a line with a thickness is probably just a specialization of filled rectangle drawing, right?

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

Sorry for the triple post, but I dug deeper in the docs and found some functions that are already present. Aren't these already covering the issue?

Drawing a line: imageproc::drawing::draw_line_segment
Drawing a thick line: imageproc::drawing::draw_filled_rect

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

Can't get it to work though:

extern crate image;
extern crate imageproc;

use image::RgbImage;
use imageproc::rect::Rect;
use imageproc::drawing::draw_filled_rect;

fn main() {
    let mut img = RgbImage::new(256, 256);
    let thickness = 10;
    draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness), [240, 240, 255]);
    img.save("output.png").unwrap();
}

Results in:

src/main.rs:16:5: 16:21 error: the trait image::image::GenericImage is not implemented for the type image::buffer::ImageBuffer<image::color::Rgb<u8>, collections::vec::Vec<u8>> [E0277]
src/main.rs:16 draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness), [240, 240, 255]);
^~~~~~~~~~~~~~~~

I'm not sure how I can use an RgbImage as a GenericImage.

If I find out, maybe I can contribute some docs with examples.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

There's only support for axis-aligned rectangles, so we still need to add code for slanted wide lines.

Your compiler error might just be because you're missing a "use image::GenericImage". If that doesn't work I'll check when I get home (about five hours from now).

More examples in the docs would be great, even if this approach doesn't end up solving the original problem.

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

Your compiler error might just be because you're missing a "use image::GenericImage".

No, that didn't help.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Ah, the last parameter to draw_filled_rect should be Rgb([240, 240, 255]), instead of just the array.

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

That didn't solve the problem either :(

use image::{Rgb, RgbImage};
// ...

fn main() {
    // ...
    draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness),
                     Rgb([240, 240, 255]));
    // ...
}

Same output as above.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Ok, I'll have a look when I get home.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Very odd. The following code works fine for me:

extern crate image;
extern crate imageproc;

use image::{
    Rgb,
    RgbImage
};

use imageproc::rect::Rect;
use imageproc::drawing::draw_filled_rect_mut;

fn main() {
    let mut img = RgbImage::new(256, 256);
    let thickness = 10;
    draw_filled_rect_mut(&mut img, Rect::at(128, 10).of_size(118, thickness), Rgb([240, 240, 255]));
    img.save("output.png").unwrap();
}

(Your code compiled too, but didn't do anything useful - I've replaced the use of draw_filled_rect with draw_filled_rect_mut so that we update the image in place.)

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Are you trying this in a new project? If so, what does your Cargo.toml file look like?

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

I copy-pasted your code and still get the same errors :(

I'm using latest versions of both image and imageproc. Used * version specifiers for quick testing:

[package]
name = "img"
version = "0.1.0"
authors = ["..."]

[dependencies]
image = "*"
imageproc = "*"

Maybe you're on a different version?

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

For some reason

image = "*" 

resulted in cargo producing a gigantic wall of complaints around not being able to find packages. However, with

image = "0.3.15"
imageproc = "*"

I can compile and run successfully on latest stable, latest nightly, and nightly from the end of last year.

from imageproc.

dbrgn avatar dbrgn commented on August 18, 2024

You're right, it works with image 0.3.15. The current verision of image is 0.6.1 though. Could imageproc maybe be updated to support that version? And/or could/should important imports from image be re-exported?

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Yes, it's pretty embarrassing that this doesn't work with more recent versions of image. I'd not noticed as I was using a fixed version of image. The breaking change looks to happen between 0.3.15 and 0.4.1.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

This works with latest image:

extern crate image;
extern crate imageproc;

use image::{
    Rgb,
    RgbImage,
    GenericImage
};

fn constraints<I>(image: &I, color: I::Pixel)
    where I: GenericImage,
    I::Pixel: 'static
{
    let x = image.height();
    println!("{}", x);
}

fn main() {
    let img = RgbImage::new(256, 256);
    constraints(&img, Rgb([0, 0, 0]));
}

Where where I'm using the same bounds as the draw_filled_rect function. So I'm none the wiser as to what's going on.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

@bvssvni @tafia Am I missing something obvious here?

from imageproc.

tafia avatar tafia commented on August 18, 2024

When I do a cargo clean then cargo build --verbose it apparently compiles 2 versions of several crates

  • png (0.4.1 and 0.3.1)
  • image (0.6.1 and 0.3.15)
  • byteorder (0.4.2 and 0.3.13)
  • bitflags (0.3.3 and 0.4.0)

If I force using image 0.6.1 (via .cargo/config file) the code works fine.
I suppose there is some conflict somewhere.

I also noted that there is a commit in image:

e7fd748 Fixed `NotEnoughData(..)` => `NotEnoughData`

which corresponds to the first warning messages I have.

EDIT: Looking at Cargo.lock is actually much simpler than using --verbose ...

from imageproc.

tafia avatar tafia commented on August 18, 2024

@theotherphil I think the issue is in your Cargo.toml / Cargo.lock => you should probably upgrade to higher version.

It specifically mentions it uses image 0.3.15. You should update the dependencies it and push it to crates.io.

[[package]]
name = "imageproc"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "conv 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "image 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
 "itertools 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "nalgebra 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "num 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
 "quickcheck 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
]

from imageproc.

korczis avatar korczis commented on August 18, 2024

Any news? Any plans to fix/implement this?

I am looking for functionality similar to http://chunkypng.com/

Any plans to implement such functions/interface?

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

I had a quick look at the documentation for that library and couldn't see anything about drawing anti-aliased lines. Which functions specifically did you have in mind?

If you're just after PNG loading and saving then this is already supported by the image library (whose image types and traits this library uses).

from imageproc.

korczis avatar korczis commented on August 18, 2024

For example this method - http://www.rubydoc.info/github/wvanbergen/chunky_png/ChunkyPNG/Canvas/Drawing#line_xiaolin_wu-instance_method

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Aha, thanks. I'll add that and the polygon function this weekend.

from imageproc.

korczis avatar korczis commented on August 18, 2024

Wow. That will be really great. Thanks a lot.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

I've made a start in #140. Take a look and let me know what you think. It's not as fast as it should be at the moment, but is hopefully correct. Is this good enough for your current use case? The initial aim of all the drawing functions was just to show points of interest on an image when debugging or verifying results of some vision algorithms, so none of them are particularly well written. This can certainly be improved though.

I'm afraid I won't get time to implement the polygon algorithm this weekend after all.

from imageproc.

theotherphil avatar theotherphil commented on August 18, 2024

Fixed by 142 and 144

from imageproc.

korczis avatar korczis commented on August 18, 2024

Works for me. Thanks.

from imageproc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.