Struct SessionBuilder

Source
pub struct SessionBuilder<'a> { /* private fields */ }
Expand description

Builds a session by setting parameters and adding input images, calling build will check all of the provided inputs to verify that texture synthesis will provide valid output

Implementations§

Source§

impl<'a> SessionBuilder<'a>

Source

pub fn new() -> Self

Creates a new SessionBuilder, can also be created via Session::builder()

Source

pub fn add_example<E: Into<Example<'a>>>(self, example: E) -> Self

Adds an Example from which a generator will synthesize a new image.

See examples/01_single_example_synthesis

§Examples
let tex_synth = texture_synthesis::Session::builder()
    .add_example(&"imgs/1.jpg")
    .build().expect("failed to build session");
Source

pub fn add_examples<E: Into<Example<'a>>, I: IntoIterator<Item = E>>( self, examples: I, ) -> Self

Adds Examples from which a generator will synthesize a new image.

See examples/02_multi_example_synthesis

§Examples
let tex_synth = texture_synthesis::Session::builder()
    .add_examples(&[&"imgs/1.jpg", &"imgs/2.jpg"])
    .build().expect("failed to build session");
Source

pub fn inpaint_example<I: Into<ImageSource<'a>>, E: Into<Example<'a>>>( self, inpaint_mask: I, example: E, size: Dims, ) -> Self

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

§Examples
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");
Source

pub fn inpaint_example_channel<E: Into<Example<'a>>>( self, mask: ChannelMask, example: E, size: Dims, ) -> Self

Inpaints an example, using a specific channel in the example image as the inpaint mask

§Examples
let tex_synth = texture_synthesis::Session::builder()
    .inpaint_example_channel(
        // Let's use inpaint the alpha channel
        texture_synthesis::ChannelMask::A,
        &"imgs/bricks.png",
        texture_synthesis::Dims::square(400)
    )
    .build().expect("failed to build session");
Source

pub fn load_target_guide<I: Into<ImageSource<'a>>>(self, guide: I) -> Self

Loads a target guide map.

If no Example guide maps are provided, this will produce a style transfer effect, where the Examples are styles and the target guide is content.

See examples/03_guided_synthesis, or examples/04_style_transfer,

Source

pub fn resize_input(self, dims: Dims) -> Self

Overwrite incoming images sizes

Source

pub fn seed(self, value: u64) -> Self

Changes pseudo-deterministic seed.

Global structures will stay same, if the same seed is provided, but smaller details may change due to undeterministic nature of multithreading.

Source

pub fn tiling_mode(self, is_tiling: bool) -> Self

Makes the generator output tiling image.

Default: false.

Source

pub fn nearest_neighbors(self, count: u32) -> Self

How many neighboring pixels each pixel is aware of during generation.

A larger number means more global structures are captured.

Default: 50

Source

pub fn random_sample_locations(self, count: u64) -> Self

The number of random locations that will be considered during a pixel resolution apart from its immediate neighbors.

If unsure, keep same as nearest neighbors.

Default: 50

Source

pub fn random_init(self, count: u64) -> Self

Forces the first n pixels to be randomly resolved, and prevents them from being overwritten.

Can be an enforcing factor of remixing multiple images together.

Source

pub fn cauchy_dispersion(self, value: f32) -> Self

The distribution dispersion used for picking best candidate (controls the distribution ‘tail flatness’).

Values close to 0.0 will produce ‘harsh’ borders between generated ‘chunks’. Values closer to 1.0 will produce a smoother gradient on those borders.

For futher reading, check out P.Harrison’s “Image Texture Tools”.

Default: 1.0

Source

pub fn guide_alpha(self, value: f32) -> Self

Controls the trade-off between guide and example maps.

If doing style transfer, set to about 0.8-0.6 to allow for more global structures of the style.

If you’d like the guide maps to be considered through all generation stages, set to 1.0, which will prevent guide maps weight “decay” during the score calculation.

Default: 0.8

Source

pub fn backtrack_percent(self, value: f32) -> Self

The percentage of pixels to be backtracked during each p_stage. Range (0,1).

Default: 0.5

Source

pub fn backtrack_stages(self, stages: u32) -> Self

Controls the number of backtracking stages.

Backtracking prevents ‘garbage’ generation. Right now, the depth of the image pyramid for multiresolution synthesis depends on this parameter as well.

Default: 5

Source

pub fn output_size(self, dims: Dims) -> Self

Specify size of the generated image.

Default: 500x500

Source

pub fn max_thread_count(self, count: usize) -> Self

Controls the maximum number of threads that will be spawned at any one time in parallel.

This number is allowed to exceed the number of logical cores on the system, but it should generally be kept at or below that number.

Setting this number to 1 will result in completely deterministic image generation, meaning that redoing generation with the same inputs will always give you the same outputs.

Default: The number of logical cores on this system.

Source

pub fn build(self) -> Result<Session, Error>

Creates a Session, or returns an error if invalid parameters or input images were specified.

Trait Implementations§

Source§

impl<'a> Default for SessionBuilder<'a>

Source§

fn default() -> SessionBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SessionBuilder<'a>

§

impl<'a> RefUnwindSafe for SessionBuilder<'a>

§

impl<'a> Send for SessionBuilder<'a>

§

impl<'a> Sync for SessionBuilder<'a>

§

impl<'a> Unpin for SessionBuilder<'a>

§

impl<'a> UnwindSafe for SessionBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.