Repository navigation
feat(rust)!: add watermark removal - #51
Conversation
Add an explicitly loaded remover, published model downloads, and reference parity tests. BREAKING CHANGE: the new Error variants require exhaustive matches to be updated. Bump the Rust crate to 0.5.0.
Write removed images atomically, document output conversion, and retain download errors when cleanup fails. Cover JPEG quality and HTTP failures, and run validation when Python tooling changes.
Keep CI focused on Rust behavior using the published P/Q models. Leave model export and Python-reference parity checks as optional manual tooling.
Use the published remover ONNX models and remove obsolete export instructions. Keep reference-parity checks available as optional manual tooling.
| .unwrap_or_else(|| std::path::Path::new(".")); | ||
| // Encode beside the destination, then atomically replace it. A failure | ||
| // leaves the old output intact and removes the temporary file on drop. | ||
| let mut file = tempfile::NamedTempFile::new_in(parent)?; |
There was a problem hiding this comment.
NamedTempFile can be touchy on permissions. Is there a need to keep/restore/change them, or are NamedTempFile's default correct here?
There was a problem hiding this comment.
I'll fix this in a follow up PR.
| quality.unwrap_or(90), | ||
| ))?; | ||
| } else { | ||
| image::DynamicImage::ImageRgba8(recovered.to_rgba8()) |
There was a problem hiding this comment.
Is there a need to check if the image has an alpha for the conversion? to_rgb for no alpha, to_rgba8 if there is one?
There was a problem hiding this comment.
I'll fix this in a follow up PR.
| fn main() { | ||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let args = Args::parse(); | ||
| if let Command::Remove { |
There was a problem hiding this comment.
When removing, it just removes the watermark, all metadata is kept (EXIF etc.)?
There was a problem hiding this comment.
No, metadata is not retained. This is true of the apply command as well.
| ) -> DynamicImage { | ||
| let (w, h, left, top) = center_crop_size_and_offset(variant, &input); | ||
| let has_alpha = input.color().has_alpha(); | ||
| let mut output = input.to_rgba32f(); |
There was a problem hiding this comment.
Maybe we can reduce the amount of copies kept? Is the original as-is needed?
There was a problem hiding this comment.
I'll fix that in a follow up PR
| The CLI writes PNG or JPEG (`--quality 90` by default for JPEG); the library | ||
| accepts decoded `DynamicImage` values. Missing or incompatible remover models | ||
| return errors. A shared remover serializes inference independently of encoders | ||
| and decoders. Existing callers incur no removal-model startup or memory cost. |
There was a problem hiding this comment.
Isn't there a memory cost if a session starts, and removes?
There was a problem hiding this comment.
Yes. That comment needs to be updated.
Summary
WatermarkRemoverand CLIremovecommand, preserving image dimensions and alpha.cargo xtask fetch-removers, with size checks to reject truncated downloads.python/; add removal tests, a benchmark, and CI coverage.Errorvariants require exhaustive matches to be updated.Validation
(Sent by AI, with oversight)