Skip to content

Commit 85877ca

Browse files
committed
pretty high confidence, could increase crop on the right if face issues later.
1 parent ebb720f commit 85877ca

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

edge_bg.png

-2.87 KB
Loading

edge_slice.png

-2 Bytes
Loading

main.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,23 @@ func ExtractMask(img *image.RGBA) *image.Alpha {
190190
return mask
191191
}
192192

193+
func GetMaskOutline(mask *image.Alpha) *image.Alpha {
194+
bounds := mask.Bounds()
195+
outline := image.NewAlpha(bounds)
196+
for y := bounds.Min.Y + 1; y < bounds.Max.Y-1; y++ {
197+
for x := bounds.Min.X + 1; x < bounds.Max.X-1; x++ {
198+
if mask.AlphaAt(x, y).A > 0 {
199+
// Check neighbors
200+
if mask.AlphaAt(x+1, y).A == 0 || mask.AlphaAt(x-1, y).A == 0 ||
201+
mask.AlphaAt(x, y+1).A == 0 || mask.AlphaAt(x, y-1).A == 0 {
202+
outline.SetAlpha(x, y, color.Alpha{A: 255})
203+
}
204+
}
205+
}
206+
}
207+
return outline
208+
}
209+
193210
func main() {
194211
bgPath := "bg-1.png"
195212
slicePath := "slice-1.png"
@@ -222,9 +239,9 @@ func main() {
222239
mask := ExtractMask(sliceRGBA)
223240

224241
// Apply Gaussian Blur (to reduce noise)
225-
// Radius 2.0, Sigma 1.0
226-
bgBlurred := blur.Gaussian(bgRGBA, 2.0)
227-
sliceBlurred := blur.Gaussian(sliceRGBA, 2.0)
242+
// Radius 3.0, Sigma 1.5
243+
bgBlurred := blur.Gaussian(bgRGBA, 3.0)
244+
sliceBlurred := blur.Gaussian(sliceRGBA, 3.0)
228245

229246
// Apply Sobel Edge Detection
230247
bgGray := SobelEdgeDetection(bgBlurred)

mask_outline.png

459 Bytes
Loading

0 commit comments

Comments
 (0)