This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 83
Add --flips-and-rotates flag #57
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6b538b
Add --flips-and-rotates flag
JD557 50a01d8
Merge 'master' into 'flip-and-rotate'
JD557 a03a11b
Run `cargo fmt` and `cargo clippy`
JD557 5fdab54
Make flips-and-rotates a subcommand instead of a flag
JD557 2d0c83b
Move flips-and-rotates logic away from the library, into the main
JD557 a576868
Remove unnecessary #[derive(Clone)]
JD557 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use structopt::StructOpt; | |
|
||
use std::path::PathBuf; | ||
use texture_synthesis::{ | ||
image::ImageOutputFormat as ImgFmt, Dims, Error, Example, ImageSource, SampleMethod, Session, | ||
image::ImageOutputFormat as ImgFmt, Dims, Error, Example, ImageSource, SampleMethod, Session, Transformation, | ||
}; | ||
|
||
fn parse_size(input: &str) -> Result<Dims, std::num::ParseIntError> { | ||
|
@@ -118,6 +118,9 @@ struct Tweaks { | |
/// Enables tiling of the output image | ||
#[structopt(long = "tiling")] | ||
enable_tiling: bool, | ||
/// Flips and rotates traning images | ||
#[structopt(long = "flips-and-rotates")] | ||
enable_flips_and_rotates: bool, | ||
} | ||
|
||
#[derive(StructOpt)] | ||
|
@@ -213,6 +216,23 @@ fn real_main() -> Result<(), Error> { | |
} | ||
} | ||
|
||
if args.tweaks.enable_flips_and_rotates { | ||
let mut transformed_examples: Vec<_> = vec![]; | ||
for example in &examples { | ||
let mut new_examples: Vec<_> = vec![ | ||
example.clone().with_transformations(vec![Transformation::FlipH]).clone(), | ||
example.clone().with_transformations(vec![Transformation::Rot90]).clone(), | ||
example.clone().with_transformations(vec![Transformation::FlipH, Transformation::Rot90]).clone(), | ||
example.clone().with_transformations(vec![Transformation::Rot180]).clone(), | ||
example.clone().with_transformations(vec![Transformation::FlipH, Transformation::Rot180]).clone(), | ||
example.clone().with_transformations(vec![Transformation::Rot270]).clone(), | ||
example.clone().with_transformations(vec![Transformation::FlipH, Transformation::Rot270]).clone(), | ||
]; | ||
transformed_examples.append(&mut new_examples); | ||
} | ||
examples.append(&mut transformed_examples); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this whole part can be made a lot simpler by just calling load_image for the example and doing the transforms here. That way, you don't actually need to change anything in the lib crate at all, as the CLI is the only part that needs to know that the example inputs need to be transformed, and ImageSource already supports just passing a raw image. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 2d0c83b |
||
(examples, gen.target_guide.as_ref()) | ||
} | ||
Subcommand::TransferStyle(ts) => (vec![Example::new(&ts.style)], Some(&ts.guide)), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider this "flips and rotates mode" different enough to warrant being in its own subcommand, as I don't really see it making sense to also add inpainting and tiling, as you kind of get a tiling effect anyway (in a way).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double check (since you mention subcommand), you mean something like?
or do you mean something else, like moving
enable_flips_and_rotates
tostruct Generate
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, like that. Not sure about the naming though, but it can be changed later if anyone comes up with a clearer and/or shorter name. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 5fdab54