/
Tag.py
75 lines (65 loc) · 1.73 KB
/
Tag.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Title: Tag.py
# Author: Juliana Hernandez
# Description:
# Pyrhon Libraries
# Imagej Libraries
from ij import IJ
from ij.plugin.frame import RoiManager
from ij.plugin.filter import Analyzer
from ij.measure import ResultsTable
import ij.measure
# User Libraries
# Name: Tag
def tag(imp, roiMan, roiTotal, color):
print "Inside of UrchinTag..."
print "imp " + str(imp)
# Set the color and line options for tagging
IJ.run(imp, "Line Width...", "line=10")
IJ.run("Colors...", "foreground=" + color + " background=black selection=magenta")
if roiMan is not None:
# Iterate through the ROIs
for roi in xrange(roiTotal):
# Select the ROI
roiMan.select(roi)
selectRoi = roiMan.getRoi(roi)
# Tag the ROI
IJ.run(imp, "Draw", "slice")
# end for loop
return 1
else:
return 0
def delete(imp, roiMan, roiTotal):
# set results table
rt = ResultsTable.getResultsTable()
# set up analyzer
analyzer = Analyzer(imp, 1, rt)
totalPixels = 0
# Set the color and line options for erasing
IJ.run("Colors...", "foreground=black background=black selection=magenta")
if roiMan is not None:
# Iterate through the ROIs
for roi in xrange(roiTotal):
# Select the ROI
roiMan.select(roi)
selectRoi = roiMan.getRoi(roi)
# measure
analyzer.measure()
meas = rt.getRowAsString(0)
newLine = meas.split(" ", 1)
pixels = float(newLine[1])
totalPixels = totalPixels + pixels
# Tag the ROI
IJ.run(imp, "Fill", "slice")
# end for loop
return totalPixels
else:
return 0
### Test the function ###
# Get image corresponding to the ROIs
#testImp = IJ.getImage()
# Open ROI manager
#rm = RoiManager.getInstance()
# Get number of objects found
#roiCount = rm.getCount()
# Test function
#print delete(testImp, rm, roiCount)