-
Notifications
You must be signed in to change notification settings - Fork 83
Add --inpaint-alpha
to CLI and API changes to derive mask from channels
#60
Add --inpaint-alpha
to CLI and API changes to derive mask from channels
#60
Conversation
There is mild refactor around ImageSource: - The original ImageSource is now DataSource - The new ImageSource has a Mask and a DataSource
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.
Hey, thanks for the PR! I've left some comments. 🙂
cli/src/main.rs
Outdated
/// Flag to extract inpaint from the example's alpha channel | ||
#[structopt(long)] | ||
inpaint_alpha: bool, |
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 realise #22 specifically mentions the alpha channel, but might want to just name this --inpaint-channel <r, g, b, a>
instead (defaulting to alpha) since you already added support for different mask channels.
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.
Not very experienced with structupt, does it support a way to set the default value only if the flag is present?
E.g.
texture-synthesis --inpaint-channel
will be texture-synthesis --inpaint-channel=a
texture-synthesis
won't be texture-synthesis --inpaint-channel=a
lib/src/utils.rs
Outdated
pub(crate) fn apply_mask(original_image: &image::RgbaImage, mask: &Mask) -> image::RgbaImage { | ||
let mut image = original_image.clone(); |
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.
This should just take image by &mut
, as now there is an unnecessary copy made that gets immediately discarded at the one call site.
} | ||
|
||
impl<'a> ImageSource<'a> { | ||
pub fn from_path(path: &'a Path) -> ImageSource<'a> { |
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.
ImageSource
already has From<AsRef<Path>>
that does this.
cli/src/main.rs
Outdated
@@ -239,6 +243,16 @@ fn real_main() -> Result<(), Error> { | |||
|
|||
let mut sb = Session::builder(); | |||
|
|||
if args.inpaint_alpha { |
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.
--inpaint
and --inpaint-channel
should probably be exclusive, structopt doesn't really support that atm, so you can just check manually and error if they are both set.
Just finished most of the changes, but I ran into lifetime issues when trying to do
Error message:
I don't have a good grasp on lifetimes, so I will have to dig into that later as I have to get back to my thesis for now. |
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.
Thanks for adding this feature!
Closing this in favor of #67 which has all the changes and does some minor cleanup, again, thanks so much for this PR, really sorry it took so long! |
No problem, happy to contribute :). |
Hey, found myself in a Hacktoberfest event this Saturday and it felt like a good opportunity to try my hand on #22 :).
Changes
To derive an inpaint mask from the alpha channel I felt it would be more "idiomatic" according to the lib to do some changes on
ImageSource
, therefore there are some minor modifications on it.--inpaint-alpha
argument to CLIMask
enumImageSource
is nowDataSource
ImageSource
is now a struct with aMask
and aDataSource
Usage
Example
Example:
Result:
(Image source: https://unsplash.com)
Checklist
rustfmt
clippy