EmbarkStudios / texture-synthesis

🎨 Example-based texture synthesis written in Rust 🦀

Home Page:http://embark.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inpaint using other image as example runtime error

MassimilianoBiancucci opened this issue · comments

commented

I'm trying to use the library directly without the CLI interface.
I'm trying the impainting example as explained inside the library in a comment over inpaint_example() method, below the cited comment:

    /// Inpaints an example. Due to how inpainting works, a size must also be
    /// provided, as all examples, as well as the inpaint mask, must be the same
    /// size as each other, as well as the final output image. Using
    /// `resize_input` or `output_size` is ignored if this method is called.
    ///
    /// To prevent sampling from the example, you can specify
    /// `SamplingMethod::Ignore` with `Example::set_sample_method`.
    ///
    /// See [`examples/05_inpaint`](https://github.com/EmbarkStudios/texture-synthesis/tree/main/lib/examples/05_inpaint.rs)
    ///
    /// # Examples
    ///
    /// ```no_run
    /// let tex_synth = texture_synthesis::Session::builder()
    ///     .add_examples(&[&"imgs/1.jpg", &"imgs/3.jpg"])
    ///     .inpaint_example(
    ///         &"masks/inpaint.jpg",
    ///         // This will prevent sampling from the imgs/2.jpg, note that
    ///         // we *MUST* provide at least one example to source from!
    ///         texture_synthesis::Example::builder(&"imgs/2.jpg")
    ///             .set_sample_method(texture_synthesis::SampleMethod::Ignore),
    ///         texture_synthesis::Dims::square(400)
    ///     )
    ///     .build().expect("failed to build session");
    /// ```

using exactly the script in this comment present in the file session.rs:122 I got this error:

thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', lib/src/ms.rs:696:18
stack backtrace:
   0: rust_begin_unwind
             at /rustc/51126be1b260216b41143469086e6e6ee567647e/library/std/src/panicking.rs:577:5
   1: core::panicking::panic_fmt
             at /rustc/51126be1b260216b41143469086e6e6ee567647e/library/core/src/panicking.rs:135:14
   2: core::panicking::panic_bounds_check
             at /rustc/51126be1b260216b41143469086e6e6ee567647e/library/core/src/panicking.rs:77:5
   3: texture_synthesis::ms::Generator::next_pyramid_level
             at ./lib/src/ms.rs:696:18
   4: texture_synthesis::ms::Generator::resolve
             at ./lib/src/ms.rs:797:17
   5: texture_synthesis::session::Session::run
             at ./lib/src/session.rs:55:9

This behavior appears only if I pass texture_synthesis::SampleMethod::Ignore as parameter for set_sample_method() of the example inside the inpaint_example method.
Instead, texture_synthesis::SampleMethod::All and an image as argument work smoothly.

I'm using cargo 1.60.0-nightly (95bb3c92b 2022-01-18)

Anyone know how to solve this bug?