Macro: "Clear outside" with multiple drawn shapes

macro
Tags: #<Tag:0x00007fd540adc268>

#1

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!


#2

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.

Best,
Stefan


#3

Thank you, it works!

The code looks like:

makeOval(420, 172, 873, 873);
roiManager("Add");
makeOval(1746, 226, 940, 940);
roiManager("Add");
makeOval(1787, 1743, 1027, 1027);
roiManager("Combine");

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

#4

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?


#5

@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.


#6

Thank you! Is working now.