Skip to content

Instantly share code, notes, and snippets.

@maweigert
Last active October 22, 2021 01:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maweigert/9f2684f36d3272786461a0c18d4ea176 to your computer and use it in GitHub Desktop.
Save maweigert/9f2684f36d3272786461a0c18d4ea176 to your computer and use it in GitHub Desktop.
Generate label image from rois in Fiji
#@ ImagePlus imp
#@ OUTPUT ImagePlus result
from ij import IJ
from ij.plugin.frame import RoiManager
result = IJ.createImage("Labeling", "16-bit black", imp.getWidth(), imp.getHeight(), 1)
ip = result.getProcessor()
rm = RoiManager.getInstance()
for index, roi in enumerate(rm.getRoisAsArray()):
ip.setColor(index+1)
ip.fill(roi)
ip.resetMinAndMax()
IJ.run(result, "glasbey inverted", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment