Macro: "Clear outside" with multiple drawn shapes

Tags: #<Tag:0x00007fd540adc268>


I would like to use the “Clear Outside” function (Edit → Clear Outside) in a macro, while having multiple shapes selected that have been created with the shape tools. Manually this can be done by holding the SHIFT key while drawing the shapes, so that all of them will be selected when using “Clear outside”.

As I said, this works manually and the code recorded by the macro recorder is as follows:

makeOval(420, 172, 873, 873);
makeOval(1746, 226, 940, 940);
setBackgroundColor(0, 0, 0);
run("Clear Outside");

However, when running this code in a macro only the last shape will be selected and thus everything except the part of the image surrounded by that last shape will be cleared.

Thanks already for any suggestions!


If you add all your ROIs to the Roi Manager you can use Roi Manager > More > OR (Combine) to create a composite selection (what you are creating when holding down Shift). With that composite ROI, Clear Outside should work as expected.



Thank you, it works!

The code looks like:

makeOval(420, 172, 873, 873);
makeOval(1746, 226, 940, 940);
makeOval(1787, 1743, 1027, 1027);

setBackgroundColor(0, 0, 0);
run("Clear Outside");


I am trying to measure the area in an image but when I used the clear outside the outside of the image that is selected become white making difficult the measurement because its include the outside into the measurement, I need the outside of the image to become black. How can i do this please?


@jahermidac, make sure that your background is set to black and foreground to white using the Color Picker

Clear Outside, Draw, Fill, … all use the values set for the foreground and background of the color picker.


Thank you! Is working now.