Struct texture_synthesis::session::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
sourceimpl<'a> SessionBuilder<'a>
impl<'a> SessionBuilder<'a>
sourcepub fn add_example<E: Into<Example<'a>>>(self, example: E) -> Self
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");
sourcepub fn add_examples<E: Into<Example<'a>>, I: IntoIterator<Item = E>>(
self,
examples: I
) -> Self
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");
sourcepub fn inpaint_example<I: Into<ImageSource<'a>>, E: Into<Example<'a>>>(
self,
inpaint_mask: I,
example: E,
size: Dims
) -> Self
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
.
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");
sourcepub fn inpaint_example_channel<E: Into<Example<'a>>>(
self,
mask: ChannelMask,
example: E,
size: Dims
) -> Self
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");
sourcepub fn load_target_guide<I: Into<ImageSource<'a>>>(self, guide: I) -> Self
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
,
sourcepub fn resize_input(self, dims: Dims) -> Self
pub fn resize_input(self, dims: Dims) -> Self
Overwrite incoming images sizes
sourcepub fn seed(self, value: u64) -> Self
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.
sourcepub fn tiling_mode(self, is_tiling: bool) -> Self
pub fn tiling_mode(self, is_tiling: bool) -> Self
Makes the generator output tiling image.
Default: false.
sourcepub fn nearest_neighbors(self, count: u32) -> Self
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
sourcepub fn random_sample_locations(self, count: u64) -> Self
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
sourcepub fn random_init(self, count: u64) -> Self
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.
sourcepub fn cauchy_dispersion(self, value: f32) -> Self
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
sourcepub fn guide_alpha(self, value: f32) -> Self
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
sourcepub fn backtrack_percent(self, value: f32) -> Self
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
sourcepub fn backtrack_stages(self, stages: u32) -> Self
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
sourcepub fn output_size(self, dims: Dims) -> Self
pub fn output_size(self, dims: Dims) -> Self
Specify size of the generated image.
Default: 500x500
sourcepub fn max_thread_count(self, count: usize) -> Self
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.
Trait Implementations
sourceimpl<'a> Default for SessionBuilder<'a>
impl<'a> Default for SessionBuilder<'a>
sourcefn default() -> SessionBuilder<'a>
fn default() -> SessionBuilder<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more