Skip to content

Commit f47d8f7

Browse files
committed
Add toggle for bounding box outline
1 parent 55a1660 commit f47d8f7

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

Tools/Centroid Center Calculator.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ <h2 class="controls-heading">Controls & Results</h2>
487487
<input type="checkbox" id="bboxToggle" class="toggle-checkbox">
488488
<span class="toggle-switch"></span>
489489
</label>
490+
<label class="toggle-label">
491+
<span class="toggle-text">Show Bounding Box</span>
492+
<input type="checkbox" id="bboxRectToggle" class="toggle-checkbox">
493+
<span class="toggle-switch"></span>
494+
</label>
490495
<label class="toggle-label">
491496
<span class="toggle-text">Show Crosshairs</span>
492497
<input type="checkbox" id="crosshairsToggle" class="toggle-checkbox">
@@ -592,6 +597,7 @@ <h3>No image selected</h3>
592597
const centroidToggle = document.getElementById('centroidToggle');
593598
const bboxToggle = document.getElementById('bboxToggle');
594599
const crosshairsToggle = document.getElementById('crosshairsToggle');
600+
const bboxRectToggle = document.getElementById('bboxRectToggle');
595601

596602
const noAlphaWarning = document.getElementById('noAlphaWarning');
597603

@@ -654,6 +660,7 @@ <h3>No image selected</h3>
654660

655661
centroidToggle.addEventListener('change', updateVisualVisibility);
656662
bboxToggle.addEventListener('change', updateVisualVisibility);
663+
bboxRectToggle.addEventListener('change', updateVisualVisibility);
657664
crosshairsToggle.addEventListener('change', updateVisualVisibility);
658665

659666
// --- Background Removal ---
@@ -875,6 +882,16 @@ <h3>No image selected</h3>
875882
// Show which pixels meet the alpha threshold
876883
applyAlphaVisualization();
877884

885+
// Draw bounding box rectangle if enabled
886+
if (bboxRectToggle.checked && currentImageState.bboxCenter && currentImageState.bboxCenter.bounds) {
887+
const b = currentImageState.bboxCenter.bounds;
888+
ctx.strokeStyle = '#ef4444';
889+
ctx.lineWidth = 2;
890+
ctx.setLineDash([6, 4]);
891+
ctx.strokeRect(b.minX, b.minY, b.maxX - b.minX, b.maxY - b.minY);
892+
ctx.setLineDash([]);
893+
}
894+
878895
const showCentroid = centroidToggle.checked;
879896
const showBbox = bboxToggle.checked;
880897
const showCrosshairs = crosshairsToggle.checked;
@@ -974,12 +991,13 @@ <h3>No image selected</h3>
974991
}
975992

976993
if (!found) {
977-
return { x: canvas.width / 2, y: canvas.height / 2 };
994+
return { x: canvas.width / 2, y: canvas.height / 2, bounds: null };
978995
}
979996

980997
return {
981998
x: minX + (maxX - minX) / 2,
982-
y: minY + (maxY - minY) / 2
999+
y: minY + (maxY - minY) / 2,
1000+
bounds: { minX, minY, maxX, maxY }
9831001
};
9841002
}
9851003

0 commit comments

Comments
 (0)