接口11/12:固定 pushed 遮罩 + multiband 融合,移除其他算法选项

遮罩算法只保留 pushed(发际线外推),融合算法只保留 multiband(多频段金字塔),
eroded/closed/feather/alpha_gradient/seamless 等旧选项从接口参数层移除。

- generate_hairline_grow: 删除 mask_type/blend_method/feather_px/color_match 参数,
  内部固定 mask_type=pushed、blend_method=multiband
- app.py 接口11/12: 删除 mask_type/blend_method/feather_px/color_match Form 参数,
  调用处改关键字传参;grow_v2 只传 image+hairline_id 即默认走最新算法
- 前端两个测试页: 删除遮罩/融合下拉选项及相关联动,固定展示 pushed 步骤
- 文档: 更新为"固定 pushed + multiband,移除其他选项"
This commit is contained in:
xsl
2026-07-11 23:31:19 +08:00
parent 1b9f3fdb6f
commit 1e6c2e54de
5 changed files with 106 additions and 179 deletions
+18 -67
View File
@@ -113,32 +113,23 @@
</div>
<div class="pf">
<label>mask_type <span class="desc">遮罩类型</span></label>
<select id="maskType">
<option value="eroded">eroded(外缘内缩,默认)</option>
<option value="closed">closed(闭合区域,未内缩)</option>
<option value="pushed">pushed(发际线外推)</option>
</select>
</div>
<div class="pf">
<label>erode_cm <span class="desc">外缘内缩距离(cm)</span></label>
<label>erode_cm <span class="desc">baseline参考内缩(cm)</span></label>
<div class="row">
<input type="number" id="erodeCm" min="0" max="5" step="0.1" value="1.2">
<input type="range" id="erodeRange" min="0" max="3" step="0.1" value="1.2">
<input type="number" id="erodeCm" min="0" max="5" step="0.1" value="0.6">
<input type="range" id="erodeRange" min="0" max="3" step="0.1" value="0.6">
</div>
</div>
<div class="pf" data-show="mask:pushed">
<label>hairline_push_cm <span class="desc">发际线外推距离(仅pushed)</span></label>
<div class="pf">
<label>hairline_push_cm <span class="desc">发际线外推距离(cm)</span></label>
<div class="row">
<input type="number" id="hairlinePushCm" min="0" max="3" step="0.1" value="1.0">
<input type="range" id="hairlinePushRange" min="0" max="3" step="0.1" value="1.0">
</div>
</div>
<div class="pf" data-show="mask:pushed">
<label>hairline_edge <span class="desc">发际线提取方式(仅pushed)</span></label>
<div class="pf">
<label>hairline_edge <span class="desc">发际线提取方式</span></label>
<select id="hairlineEdge">
<option value="column">column(逐列最低点,稳定)</option>
<option value="contour">contour(形态学轮廓,精确)</option>
@@ -146,30 +137,7 @@
</div>
<div class="pf">
<label>blend_method <span class="desc">接缝融合算法</span></label>
<select id="blendMethod">
<option value="feather">feather(高斯羽化,默认)</option>
<option value="alpha_gradient">alpha_gradient(距离变换内渐变)</option>
<option value="seamless">seamless(泊松无缝克隆)</option>
<option value="multiband">multiband(多频段金字塔融合)</option>
</select>
</div>
<div class="pf" data-show="blend:feather,alpha_gradient,multiband">
<label>color_match <span class="desc">颜色校正前置</span></label>
<div class="chk"><input type="checkbox" id="colorMatch"><span style="font-size:13px">融合前对生成图做 Reinhard 颜色校正(消除整体色差,seamless 自动跳过)</span></div>
</div>
<div class="pf" data-show="blend:feather,alpha_gradient">
<label>feather_px <span class="desc">羽化/渐变过渡宽度(px)</span></label>
<div class="row">
<input type="number" id="featherPx" min="1" max="80" step="1" value="15">
<input type="range" id="featherRange" min="1" max="60" step="1" value="15">
</div>
</div>
<div class="pf" data-show="blend:multiband">
<label>mb_levels <span class="desc">多频段金字塔层数(仅multiband)</span></label>
<label>mb_levels <span class="desc">多频段金字塔层数</span></label>
<div class="row">
<input type="number" id="mbLevels" min="2" max="6" step="1" value="5">
<input type="range" id="mbLevelsRange" min="2" max="6" step="1" value="5">
@@ -291,9 +259,8 @@ function renderMetrics(d) {
{ label: 'hairline_id', value: d.hairline_id },
{ label: 'swap_mode', value: d.swap_mode },
{ label: 'seg_model', value: d.seg_model },
{ label: 'mask_type', value: d.mask_type },
{ label: 'mask', value: d.mask_type },
{ label: 'blend', value: d.blend_method },
{ label: 'color_match', value: d.color_match },
{ label: 'mb_levels', value: d.mb_levels },
{ label: 'hairline_push', value: d.hairline_push_cm + 'cm' },
{ label: 'hairline_edge', value: d.hairline_edge },
@@ -317,12 +284,9 @@ function renderResult(d) {
$('finalOut').onclick = function(){ zoom(this.src); };
renderMetrics(d);
const grid = $('stepsGrid'); grid.innerHTML = '';
// 按 mask_type 过滤步骤:pushed 只显示 baseline/upper/头发分割/发际线/外推;
// eroded/closed 只显示 baseline/upper/头发分割/填充/闭合,不显示发际线/外推。
const mt = d.mask_type;
const showKeys = new Set(['baseline_overlay','upper_overlay','hair_seg_overlay','mask_overlay','mask','swap_raw','hard_paste','alpha','final']);
if (mt === 'pushed') { showKeys.add('hairline_overlay'); showKeys.add('pushed_overlay'); }
else { showKeys.add('top_fill_overlay'); showKeys.add('closed_overlay'); }
// 固定 pushed:只展示 pushed 相关步骤(不展示 top_fill/closed
const showKeys = new Set(['baseline_overlay','upper_overlay','hair_seg_overlay',
'hairline_overlay','pushed_overlay','mask_overlay','mask','swap_raw','hard_paste','alpha','final']);
STEPS.filter(st => showKeys.has(st.key)).forEach(st =>
grid.appendChild(stepCard(st.title, st.sub, pick(s, st.key))));
}
@@ -343,18 +307,13 @@ async function submitTest() {
form.append('hairgrow_strength', $('hgStrength').value || '0.75');
form.append('is_hr', $('isHr').checked ? 'true' : 'false');
form.append('seg_model', $('segModel').value);
form.append('mask_type', $('maskType').value);
form.append('erode_cm', $('erodeCm').value || '1.2');
setStatus('正在请求 mask_type=' + $('maskType').value
+ ' hairline_push_cm=' + ($('hairlinePushCm').value||'1.0')
form.append('erode_cm', $('erodeCm').value || '0.6');
setStatus('正在请求(固定 pushed + multiband hairline_push_cm=' + ($('hairlinePushCm').value||'1.0')
+ ' hairline_edge=' + $('hairlineEdge').value
+ '(换发型走 GPU,约 10~15s...', 'info');
form.append('swap_mode', $('swapMode').value);
form.append('blend_method', $('blendMethod').value);
form.append('feather_px', $('featherPx').value || '15');
form.append('edge_erode_px', $('edgeErodePx').value || '3');
form.append('denoising_strength', $('denoise').value || '0.6');
form.append('color_match', $('colorMatch').checked ? 'true' : 'false');
form.append('mb_levels', $('mbLevels').value || '5');
form.append('hairline_push_cm', $('hairlinePushCm').value || '1.0');
form.append('hairline_edge', $('hairlineEdge').value);
@@ -397,7 +356,7 @@ function copyJson() {
}
// ---- 参数持久化 + 联动 ----
const FIELDS = ['token','genBackend','hairlineId','swapMode','segModel','maskType','erodeCm','blendMethod','featherPx','edgeErodePx','denoise','hgStrength','mbLevels','hairlinePushCm','hairlineEdge'];
const FIELDS = ['token','genBackend','hairlineId','swapMode','segModel','erodeCm','edgeErodePx','denoise','hgStrength','mbLevels','hairlinePushCm','hairlineEdge'];
function saveField(id) { try { localStorage.setItem('if11_' + id, $(id).type === 'checkbox' ? ($(id).checked?'1':'0') : $(id).value); } catch(e){} }
function linkNumRange(numId, rngId) {
const num = $(numId), rng = $(rngId);
@@ -419,42 +378,34 @@ document.addEventListener('DOMContentLoaded', () => {
});
try { $('isHr').checked = localStorage.getItem('if11_isHr') === '1'; } catch(e){}
$('isHr').addEventListener('change', () => saveField('isHr'));
try { $('colorMatch').checked = localStorage.getItem('if11_colorMatch') === '1'; } catch(e){}
$('colorMatch').addEventListener('change', () => saveField('colorMatch'));
linkNumRange('erodeCm','erodeRange');
linkNumRange('featherPx','featherRange');
linkNumRange('edgeErodePx','edgeErodeRange');
linkNumRange('denoise','denoiseRange');
linkNumRange('hgStrength','hgStrengthRange');
linkNumRange('mbLevels','mbLevelsRange');
linkNumRange('hairlinePushCm','hairlinePushRange');
// 初始化滑块值
$('erodeRange').value = Math.min(3, parseFloat($('erodeCm').value)||1.2);
$('featherRange').value = Math.min(60, parseFloat($('featherPx').value)||15);
$('erodeRange').value = Math.min(3, parseFloat($('erodeCm').value)||0.6);
$('edgeErodeRange').value = Math.min(30, parseFloat($('edgeErodePx').value)||3);
$('denoiseRange').value = Math.min(1.0, parseFloat($('denoise').value)||0.6);
$('hgStrengthRange').value = Math.min(1.0, parseFloat($('hgStrength').value)||0.75);
$('mbLevelsRange').value = Math.min(6, Math.max(2, parseFloat($('mbLevels').value)||5));
$('hairlinePushRange').value = Math.min(3, parseFloat($('hairlinePushCm').value)||1.0);
// 参数联动:按 gen_backend / blend_method 显隐无用参数(data-show 声明)
// 参数联动:按 gen_backend 显隐无用参数(data-show 声明,遮罩/融合已固定无选项
function applyVisibility() {
const gen = $('genBackend').value, bm = $('blendMethod').value, mt = $('maskType').value;
const gen = $('genBackend').value;
document.querySelectorAll('.pf[data-show]').forEach(el => {
const conds = el.dataset.show.split(',').map(s => s.trim());
let vis = true;
conds.forEach(c => {
const [k, v] = c.split(':');
if (k === 'gen' && v !== gen) vis = false;
if (k === 'blend' && v !== bm) vis = false;
if (k === 'mask' && v !== mt) vis = false;
});
el.style.display = vis ? '' : 'none';
});
}
$('genBackend').addEventListener('change', applyVisibility);
$('blendMethod').addEventListener('change', applyVisibility);
$('maskType').addEventListener('change', applyVisibility);
applyVisibility();
});
</script>