Creating tumor margins in m6

I am interested in using the script Pete made for defining an inner and outer margin around the tumor. However, I don’t know how to adjust the script so that it works in version m6. Is there someone that managed to convert the script?



Assuming you mean the script here, I’ve quickly updated it for m6 at

Please let me know if you find any problems with it.


Just updated the version with multiple margins here:

Original description here:

As a bonus, now includes the central tumor region, which I had left out before.

1 Like

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:

Pete’s script:




1 Like

Not entirely sure what is going on in the images due to all of the colors differences (I think both the tumor and tissue boundaries are red in mine), but it looks like in the first Pete’s script image you haven’t adjusted the tissue boundary, while in the second image you adjusted both the tumor and tissue boundaries. Pete’s script should be checking for the tissue boundary as well, so not really clear what is going on there. Glad one of them works for you though.

Note that as of M5 or so, you have the additional option of using the distance transform to get the exact distribution of distances between objects and annotation edges, and in M6 it can be easily scripted. Though, it still shows distances outside of annotations and you would need to create an inverse annotation to the tumor to get the distances “into” the tumor.