Hi Pete and research_associate,
I tried both of your scripts and they worked like a charm. Thank you both for the input!
I have an example of a case where I don’t want the invasive margin in a specific region of the tumor. I adjusted the tissue detection to leave that part out. The result for both scripts are a little different here. Indeed, the outer invasive margin was not created for this region, but in Pete’s script I still got the inner invasive margin (or that region disappeared, depending on how I adjusted the tissue detection). This didn’t happen in Research_Associate script (which was what I wanted). I included some screenshots to show the difference.
Research associate script: