-
Notifications
You must be signed in to change notification settings - Fork 0
/
IdentifyTunicate.py
56 lines (45 loc) · 1.7 KB
/
IdentifyTunicate.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
# Title: IdentifyTunicate.py
# Author: Juliana Hernandez
# Description: Identifies Macro
# Python Libraries
# Imagej Libraries
from ij import IJ, ImagePlus
from ij.process import ImageProcessor, FloatProcessor
from ij.plugin import ImageCalculator
from ij.plugin.frame import RoiManager
# User Libraries
from UrchinLib import ProcessHSB
def identifyTunicate(imp):
# Clear ROI manager
rm = RoiManager.getInstance()
if rm is not None:
rm.reset()
# Get hue from HSB stack
impHue = ProcessHSB.getHue(imp)
width = impHue.width
height = impHue.height
# Get processor
ipHue = impHue.getProcessor().convertToFloat()
huePixels = ipHue.getPixels()
# Get macro hue because it is the same color
newPixels = map(ProcessHSB.macroHue, huePixels)
ipNew = FloatProcessor(width, height, newPixels)
impTunicate = ImagePlus("MacroHue", ipNew)
# Bring brightness into the equation
impBrightness = ProcessHSB.getBrightness(imp)
IJ.run(impBrightness, "Auto Threshold", "method=MaxEntropy white")
#IJ.run(impBrightness, "Analyze Particles...", "size=10000-Infinity circularity=0.10-1.00 show=Masks in_situ") # "add" right after "include" to include roi to manager
# Logic AND pictures together
ic = ImageCalculator()
impTunicateMask = ic.run("AND create", impTunicate, impBrightness)
IJ.run(impTunicateMask, "8-bit", "") # convert to 8-bit
impTunicate.close()
impBrightness.close()
IJ.run(impTunicateMask, "Analyze Particles...", "size=10000-Infinity circularity=0.50-1.00 show=Masks add in_situ") # "add" right after "include" to include roi to manager
impTunicateMask.close()
#imp.show()
#rm = RoiManager.getInstance()
#return rm
#testImp = IJ.getImage()
#result = identifyTunicate(testImp)
#print type(result)