ycenter = random.randint(0, height) # discard positions that would generate overlapping cells if not cellOverlap(xcenter, ycenter, celldiam, centers): centers.append([xcenter, ycenter]) # print("Spot "+str(count)+" center: "+str(centers[count])) count += 1 # work on a copy of the image from ij.plugin import Duplicator imp2 = Duplicator().run(imp, 1, channels, 1, 1, 1, 1) # clear the existing channel imp2.setDisplayMode(IJ.COLOR) imp2.setC(targetChannel) IJ.run(imp2, "Select All", "") IJ.setBackgroundColor(0, 0, 0) IJ.run(imp2, "Clear", "slice") # draw white circles to simulate cells IJ.setForegroundColor(255, 255, 255) for point in centers: drawSpot(point, celldiam) # save the simulated image IJ.saveAs(imp2, "Tiff", os.path.join(srcDir, basename + " sim " + str(trial) + ".tif")) imp2.close()