This is how I did it. I read various posts on autotiling. This method checks the if there's a tile north, east, west and south of the current tile. Then sets the current one according to the bitwise value.
1) use noise to fill a tilemap with solid tiles
2) go though every tile
--- if current tile isn't empty, run the following function on it: