fix: tighten scale adjust patch compositing

This commit is contained in:
134 2026-07-04 22:06:35 +08:00
parent 290f36b44e
commit dde159ea7c
2 changed files with 25 additions and 5 deletions

View File

@ -1986,7 +1986,7 @@ async function buildScaleAdjustCompositeClipMaskPatch(params: {
const alpha = await sharp(Buffer.from(maskBuffer), {
raw: { channels: 1, height: box.height, width: box.width },
})
.blur(Math.max(1.4, Math.min(box.width, box.height) * 0.012))
.blur(Math.max(0.8, Math.min(box.width, box.height) * 0.006))
.raw()
.toBuffer();
const rgba = Buffer.alloc(box.width * box.height * 4);
@ -2425,6 +2425,17 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
),
width: placement.sourceBox.width,
});
const sourceCompositeClipMask = dilateScaleAdjustStructureMask({
height: placement.sourceBox.height,
mask: filteredSourceBbox ? filteredSourceMask : highConfidenceSourceMask,
radius: Math.max(
1,
Math.round(
Math.min(placement.sourceBox.width, placement.sourceBox.height) * 0.003
)
),
width: placement.sourceBox.width,
});
const sourceWashPatch = await buildScaleAdjustMaskWashPatch({
background,
box: placement.sourceBox,
@ -2432,7 +2443,7 @@ async function buildScaleAdjustRmbgStructureLockedComposite(params: {
});
const compositeClipMaskPatch = await buildScaleAdjustCompositeClipMaskPatch({
box: placement.sourceBox,
maskBuffer: sourceWashMask,
maskBuffer: sourceCompositeClipMask,
});
const subjectCutout = await sharp(cleanedCutout, { failOn: "none" })
@ -2651,6 +2662,15 @@ async function buildScaleAdjustStructureLockedComposite(params: {
),
width: placement.sourceBox.width,
});
const sourceCompositeClipMask = dilateScaleAdjustStructureMask({
height: placement.sourceBox.height,
mask,
radius: Math.max(
1,
Math.round(Math.min(placement.sourceBox.width, placement.sourceBox.height) * 0.003)
),
width: placement.sourceBox.width,
});
const sourceWashPatch = await buildScaleAdjustMaskWashPatch({
background,
box: placement.sourceBox,
@ -2658,7 +2678,7 @@ async function buildScaleAdjustStructureLockedComposite(params: {
});
const compositeClipMaskPatch = await buildScaleAdjustCompositeClipMaskPatch({
box: placement.sourceBox,
maskBuffer: sourceWashMask,
maskBuffer: sourceCompositeClipMask,
});
const subjectCrop = await sharp(sourceBuffer, { failOn: "none" })
.extract(sourceSubjectBox)

View File

@ -207,8 +207,8 @@ const SCALE_ADJUST_RECTANGULAR_SEAM_CHANGE_THRESHOLD = 18;
const SCALE_ADJUST_RECTANGULAR_SEAM_MIN_EDGE_DIFF = 5;
const SCALE_ADJUST_RECTANGULAR_SEAM_MAX_EDGE_DIFF = 54;
const SCALE_ADJUST_RECTANGULAR_SEAM_EDGE_INCREASE = 2.5;
const SCALE_ADJUST_RECTANGULAR_SEAM_PAIR_RUN_RATIO = 0.11;
const SCALE_ADJUST_RECTANGULAR_SEAM_PAIR_TRANSITION_RATIO = 0.18;
const SCALE_ADJUST_RECTANGULAR_SEAM_PAIR_RUN_RATIO = 0.05;
const SCALE_ADJUST_RECTANGULAR_SEAM_PAIR_TRANSITION_RATIO = 0.07;
const SCALE_ADJUST_RECTANGULAR_SEAM_STRONG_RUN_RATIO = 0.1;
const SCALE_ADJUST_RECTANGULAR_SEAM_STRONG_TRANSITION_RATIO = 0.26;
const SCALE_ADJUST_RECTANGULAR_SEAM_VERY_STRONG_RUN_RATIO = 0.55;