To create the donnut shape ROI, we will select two consecutive circles and use XOR logical operator, the new shape will be added to the Roimanager.
Theoretically , it should work but the number of pixels is finite. The computation work in a continuous space but not in a discrete one. That means that Diff can be 0 or round up to 0 because the microalgae is too small to begin with. In this case, the new created circle will be the same as the previous one. By consequence, XOR of two same ROIS is void and no new ROI can be created. If we force the creation of a Roi, the macro will ceased to run as there is no active selection on the image. A way to avoid that is to measure after roiManager("XOR") and test the area. If Area equal the size of the window (it is of 184 µm by 184 µm that is 34178) that means that indeed XOR operation is void and the loop need to jump to the iteration.
That explains the first line of the following excerpt. We initialise a variable Testcount at 0. This variable will be decreased by 1 each time XOR is void and avoid the crash of the macro.