diff --git a/app/api/canvas/local-edit/route.ts b/app/api/canvas/local-edit/route.ts index fc82e2a42..299e71aa2 100644 --- a/app/api/canvas/local-edit/route.ts +++ b/app/api/canvas/local-edit/route.ts @@ -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) diff --git a/lib/canvas/generate-image.ts b/lib/canvas/generate-image.ts index 0c7d4f018..77cf52646 100644 --- a/lib/canvas/generate-image.ts +++ b/lib/canvas/generate-image.ts @@ -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;