Skip to content

implement boost support#56

Open
seanluong wants to merge 2 commits into
smartcrop:masterfrom
seanluong:master
Open

implement boost support#56
seanluong wants to merge 2 commits into
smartcrop:masterfrom
seanluong:master

Conversation

@seanluong
Copy link
Copy Markdown

I came across this Python version of https://github.com/jwagner/smartcrop.js working on a different project. I already implemented boosting for the vendored version of this library in that project so I thought that I should contribute that implementation back here.

This PR adds a Boost dataclass (x, y, width, height, weight) that callers can pass to crop() and analyse() to bias crop selection toward regions of interest (e.g. detected faces).

Boost coordinates are prescaled alongside the image when prescaling fires. boost_weight (default 100.0) controls the global influence of boosts.

Adds a Boost dataclass (x, y, width, height, weight) that callers can pass
to crop() and analyse() to bias crop selection toward regions of interest
(e.g. detected faces). Based on the boost feature in smartcrop.js, with the
difference that boost data is kept in a separate float32 array rather than
the alpha channel.

Boost coordinates are prescaled alongside the image when prescaling fires.
boost_weight (default 100.0) controls the global influence of boosts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@derVedro derVedro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me.

Comment thread smartcrop/library.py Outdated
skin_color: tuple[float, float, float] = DEFAULT_SKIN_COLOR
skin_threshold: float = 0.8
skin_weight: float = 1.8
boost_weight: float = 100.0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about using such a high weight value? All other project-related weights are about two orders of magnitude smaller.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I've been thinking of a good way to set the value for this but maybe it's not really needed as users can provide a weight for each boosted area themselves.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code.

boost_weight was a global multiplier (default 100.0) applied on top of
per-boost weights, making boosted regions ~43x stronger than the maximum
non-boosted pixel score. Removing it lets Boost.weight operate in the
same units as skin_weight, saturation_weight, etc., giving callers
intuitive control without a hidden scaling factor.
@seanluong seanluong requested a review from derVedro May 18, 2026 14:22
Copy link
Copy Markdown
Contributor

@derVedro derVedro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, 👌

@derVedro
Copy link
Copy Markdown
Contributor

@davidfischer-ch
If you okay with it too, it could be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants