So this is a problem in a small part of my FRET analysis pipeline. I don’t have much time to spend fixing all the dirty code, so I resigned to waitforuser ROI deletion. But the point is for the script to run without user interaction.
My problem is with deleting ROIs by index in a jython script for Fiji/ImageJ2. Mainly that it deletes everything… I have verified that the count is correct, the size is correct, the selection of the count(i) is correct…
It might be a bug, but it’s probably just something stupid. Hopefully someone more experienced will spot my glaring mistake.
Sometimes everything is deleted, sometimes upon repeated iterations more and more are deleted…
Usually this is the result of the prints, yet everything is still deleted:
The commented out commands are just a few things I tested FYI. I also tried using rm.getIndex(), no luck. Why so many deselects? I have tried many combinations as I figured it was probably a selection issue… but it doesn’t seem to be.
from ij.plugin.frame import RoiManager
from ij import IJ
from ij import IJ, WindowManager, ImagePlus
def ROIstuff():
rm = RoiManager().getInstance()
# This selects the intended ROI..
#rm.select(3)
# This deselects successfully..
#rm.runCommand('Deselect')
total_rois = rm.getCount()
print "count = ", total_rois
for roi in range(total_rois):
print "ROI# = ", str(roi)
rm.runCommand('Deselect')
# This gets the correct size (float).. only one image is open.
imp = WindowManager.getCurrentImage()
rm.select(roi)
size = imp.getStatistics().area
print "Size = ", size
rm.runCommand('Deselect')
if size < 140:
print "Too small, Deleting"
rm.select(roi)
rm.runCommand('Delete')
rm.runCommand('Deselect')
elif size > 1000:
print "Too large, deleting"
rm.select(roi)
rm.runCommand('Delete')
rm.runCommand('Deselect')
else:
rm.runCommand("Deselect")
continue
ROIstuff()
Thank you for your attention,
Sverre