aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-05 16:29:12 -0800
committerChristian C <cc@localhost>2025-03-05 16:29:12 -0800
commit12de92c487469b44912c614fc21038cdb07c1a81 (patch)
tree22d1d161c8ade3522c1435ebedee80721e3dbe28 /src
parent74e46ee7709785f91e04ac42619e4a7e9f90bc18 (diff)
Perimeter pixel check
Diffstat (limited to 'src')
-rw-r--r--src/lib/seg/util.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/seg/util.c b/src/lib/seg/util.c
index d7b91b1..22a75cc 100644
--- a/src/lib/seg/util.c
+++ b/src/lib/seg/util.c
@@ -11,6 +11,43 @@ size_t xy_to_coord(size_t x, size_t y, uint32_t width, uint32_t height)
return x + y*width;
}
+// Determine if coordinate is on a mask boundary
+// Assumes mask is (WxH)
+bool_t is_on_mask_boundary(uint16_t* mask, uint32_t width, uint32_t height, size_t x, size_t y)
+{
+ size_t starting_coord = xy_to_coord(x, y, width, height);
+ size_t proposed_position;
+ uint16_t current_value = mask[starting_coord];
+
+ // Left neighbor
+ if (x != 0) {
+ proposed_position = xy_to_coord(x-1, y, width, height);
+ if (mask[proposed_position] != current_value) {
+ return TRUE;
+ }
+ }
+ // Right neighbor
+ if ((x+1) != width) {
+ proposed_position = xy_to_coord(x+1, y, width, height);
+ if (mask[proposed_position] != current_value) {
+ return TRUE;
+ }
+ }
+ if (y != 0) {
+ proposed_position = xy_to_coord(x, y-1, width, height);
+ if (mask[proposed_position] != current_value) {
+ return TRUE;
+ }
+ }
+ if ((y+1) != height) {
+ proposed_position = xy_to_coord(x, y+1, width, height);
+ if (mask[proposed_position] != current_value) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
// Dilate masks by one 4-connected pixel
uint16_t* dilate(uint16_t* mask, uint32_t width, uint32_t height)
{