# Simple "edge" detection

**URL:** <https://forum.xojo.com/t/simple-edge-detection/24047>\
**Category:** General\
**Created:** [May 4, 2015, 9:16pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047 "2015-05-04T21:16:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [May 4, 2015, 9:16pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047/1 "2015-05-04T21:16:00Z")

</div>

I just can’t get around this.  
I have a 2D array with each cell consisting of ONE character (either a “.” or “#”) where the “.” is a “floor” and the “#” is a “wall”

what I need to do is convert all the “FLOOR” that is OUTSIDE the outer wall to a “+” to represent “dirt” for lack of a better description

So I’d like this

```auto
..###.###..
..#.#.#.#..
..#.#.#.#..
###.#.#.###
#...#.#...#
#..#...#..#
#...#.#...#
###..#.###.
..#.....#..
..#######..
```

to become This

```auto
++###+###++
++#.#+#.#++
++#.#+#.#++
###.#+#.###
#...#+#...#
#..#+++#..#
#...#+#...#
###..#.###+
++#.....#++
++#######++
```

The problem is there are vertical and horizontal INTERNAL walls, so just crossing a wall doesn’t mean you went from inside to outside

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 4, 2015, 9:24pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047/2 "2015-05-04T21:24:54Z")

</div>

I would enclose the entire thing in one more set of dots and flood-fill.  
This

```auto
..###.###..
..#.#.#.#..
..#.#.#.#..
###.#.#.###
#...#.#...#
#..#...#..#
#...#.#...#
###..#.###.
..#.....#..
..#######..
```

Becomes

```auto
.............
...###.###...
...#.#.#.#...
...#.#.#.#...
.###.#.#.###.
.#...#.#...#.
.#..#...#..#.
.#...#.#...#.
.###..#.###..
...#.....#...
...#######...
.............
```

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [May 4, 2015, 9:33pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047/3 "2015-05-04T21:33:48Z")

</div>

[http://en.wikipedia.org/wiki/Point\_in\_polygon](http://en.wikipedia.org/wiki/Point_in_polygon)

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [May 4, 2015, 9:58pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047/4 "2015-05-04T21:58:05Z")

</div>

> [@184769:@Tim Hare](#):
>
> I would enclose the entire thing in one more set of dots and flood-fill.

worked perfectly… slapping forehead for not thinking of this one myself 🙂

Array is temp\_level  
replace exterior “:” characters with “+” characters

call flood\_fill 1,0 // X is one-based, but Y is zero based

```auto
  If x<1 Or y<0 Then Exit Sub
  If y>temp_level.Ubound Then Exit Sub
  If x>temp_level(y).Len Then Exit Sub
  
  //
  If Mid(temp_level(y),x,1)=":" Then 
    temp_level(y)=Left(temp_level(y),x-1)+"+"+Mid(temp_level(y),x+1)
    //
    flood_fill(x+1,y)
    flood_fill(x-1,y)
    flood_fill(x,y+1)
    flood_fill(x,y-1)
  End If
```

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:44pm UTC](https://forum.xojo.com/t/simple-edge-detection/24047/5 "2020-10-29T17:44:40Z")

</div>


