Autotile Border Sprites For Noise Generated Terrain

I am currently making an action roguelike with random terrain.
I Have already figured out how to create The Terrain and then surround the Terrain objects with another border object, see screenshots for reference.
The next step would be to automatically tile the terrain, so the border isnt just the whole tile but just the outer pixels so when i replace the sprite textures with the real textures it looks like the terrain isnt made out of single tiles but rather like a whole sprite. I have created animations for the border tile for every possible variation (left, right,…,corners facing outward, corners facing inwards).

I Have had some luck with the outer lines (left, right, etc.) but both the inner and outer corners are very tricky.

I have spent way to much time trying every single trick in the book like having checker objects or checking point inside an object and this is as far as i got.

A detailed explaination of how this could be implemented would be nice but any tips or examples would be appreciated aswell.

Also tried to implement the inner corners but the logic is difficult as i would have to check the object over a diagonal.




PS: English is not my first language so if there is an issue or missunderstanding i am glad to explain further.