-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoiCenter.py
55 lines (51 loc) · 1.82 KB
/
RoiCenter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from ij import IJ, ImagePlus;
from ij.plugin.frame import RoiManager;
from ij.process import ImageStatistics as IS;
from ij.gui import PolygonRoi;
from ij.gui import Roi;
from ij.measure import ResultsTable;
from operator import itemgetter, attrgetter;
imp = IJ.getImage();
rm = RoiManager.getRoiManager();
rt = ResultsTable()
# IJ.run("Set Measurements...", "centroid redirect=None decimal=3");
# rm.runCommand(imp,"Measure");
# Create a new list to store the mean intensity values of each blob:
centroids = []
n = 0
for roi in RoiManager.getInstance().getRoisAsArray():
imp.setRoi(roi)
stats = imp.getStatistics(IS.CENTROID)
rt.incrementCounter() # Adds a row in Results table
#rt.addValue adds a value corresponding to column name
# n = n + 1;
n = RoiManager.getInstance().getRoiIndex(roi)
rt.addValue("No.", n)
rt.addValue("Slice", roi.getTPosition())
rt.addValue("Label", roi.getName())
rt.addValue("xCentroid", stats.xCentroid);
rt.addValue("yCentroid", stats.yCentroid);
spot=roi.getName()
centroids.append([n, stats.xCentroid, stats.yCentroid])
# print(centroids)
sortedCentroids = sorted(centroids, key=itemgetter(1))
if (sortedCentroids[0][2] < sortedCentroids[1][2]):
rm.select(sortedCentroids[0][0]);
rm.runCommand("Rename", "Top-Left");
rm.select(sortedCentroids[1][0]);
rm.runCommand("Rename", "Bottom-Left");
rm.select(sortedCentroids[2][0]);
rm.runCommand("Rename", "Top-Right");
rm.select(sortedCentroids[3][0]);
rm.runCommand("Rename", "Bottom-Right");
else:
rm.select(sortedCentroids[0][0]);
rm.runCommand("Rename", "Bottom-Left");
rm.select(sortedCentroids[1][0]);
rm.runCommand("Rename", "Top-Left");
rm.select(sortedCentroids[2][0]);
rm.runCommand("Rename", "Bottom-Right");
rm.select(sortedCentroids[3][0]);
rm.runCommand("Rename", "Top-Right");
print(sortedCentroids)
rt.show("Center")