105 lines
3.5 KiB
Python
105 lines
3.5 KiB
Python
###################################################################################################
|
|
# Example of using ImageJ functionalities through ijutils.
|
|
###################################################################################################
|
|
|
|
import datetime
|
|
from ijutils import *
|
|
import java.awt.Color as Color
|
|
|
|
import ch.psi.pshell.imaging.Filter as Filter
|
|
from ch.psi.pshell.imaging.Overlays import *
|
|
import ch.psi.pshell.imaging.Pen as Pen
|
|
|
|
|
|
roi_center = (800, 600)
|
|
roi_radius = 600
|
|
integration_count = 10
|
|
integration_continuous = False
|
|
integration_partial = False
|
|
frames = []
|
|
|
|
roi = (roi_center[0] - roi_radius, roi_center[1] - roi_radius, 2* roi_radius, 2*roi_radius)
|
|
|
|
|
|
color_roi = Color(0, 128, 0)
|
|
|
|
renderer = show_panel(img)
|
|
renderer.clearOverlays()
|
|
ov_roi_shape = Ellipse(Pen(color_roi, 0,), java.awt.Point(roi[0], roi[1]), java.awt.Dimension(roi[2], roi[3]))
|
|
ov_roi_bound = Rect(Pen(color_roi, 0, Pen.LineStyle.dotted), java.awt.Point(roi[0], roi[1]), java.awt.Dimension(roi[2], roi[3]))
|
|
ov_roi_center = Crosshairs(Pen(color_roi, 0), java.awt.Point(roi_center[0],roi_center[1]), java.awt.Dimension(15,15))
|
|
|
|
renderer.addOverlays([ov_roi_shape, ov_roi_bound,ov_roi_center])
|
|
|
|
|
|
def in_roi(x,y):
|
|
return math.hypot(x-roi_radius, y-roi_radius) < roi_radius
|
|
|
|
|
|
def integrate (ips):
|
|
for i in range(len(ips)):
|
|
if i==0:
|
|
aux = new_image(roi[2], roi[3], image_type="float", title = "sum", fill_color = None)
|
|
op_image(aux, ips[i], "add", float_result=True, in_place=True)
|
|
op_const(aux, "divide", len(ips), in_place=True)
|
|
return aux
|
|
|
|
|
|
last_ret = (None, None)
|
|
x=None
|
|
def detect_led(ip):
|
|
global roi_center, roi_radius, integration_count, integration_continuous, integration_partial, frames
|
|
global count , last_ret , x
|
|
x=ip
|
|
aux = sub_image(ip, roi[0], roi[1], roi[2], roi[3])
|
|
grayscale(aux)
|
|
#gaussian_blur(aux)
|
|
|
|
if (integration_count>1):
|
|
frames.append(aux)
|
|
if len(frames) >integration_count:
|
|
del frames[0]
|
|
if not integration_continuous:
|
|
if (len(frames)< integration_count):
|
|
if last_ret[1] is not None: invert(last_ret[1])
|
|
return last_ret
|
|
if (not integration_partial) and len(frames) <integration_count:
|
|
return last_ret
|
|
aux = integrate(frames)
|
|
|
|
#aux = get_channel(aux, "blue")
|
|
invert(aux)
|
|
#subtract_background(aux)
|
|
#Tested ok: Huang, Mean, MaxEntropy, Percentile, Triangle, Yen
|
|
auto_threshold(aux, method = "Percentile")
|
|
#binary_open(aux)
|
|
(results,output) = analyse_particles(aux, 250,1000,
|
|
fill_holes = True, exclude_edges = False, print_table=False,
|
|
output_image = "outlines", minCirc = 0.3
|
|
, maxCirc = 1.0)
|
|
r=results
|
|
|
|
|
|
points = ""
|
|
npoints = 0
|
|
for row in range (r.counter):
|
|
if in_roi(r.getValue("XM",row), r.getValue("YM",row)):
|
|
points = points + " (" + str(int(r.getValue("XM", row))+roi[0]) + ", " + str(int(r.getValue("YM", row))+roi[1]) + ")"
|
|
npoints = npoints + 1
|
|
print str(npoints) + " - " + points
|
|
|
|
last_ret = (results,output)
|
|
if not integration_continuous:
|
|
frames = []
|
|
|
|
if npoints!=12:
|
|
save_image(op_image(aux, output,"xor", in_place=False), "{images}/" + str(datetime.datetime.now().strftime("%Y%m%d_%H%M%S"))+".png", "png")
|
|
#return (results,aux)
|
|
return (results,output)
|
|
|
|
|
|
|
|
|
|
|
|
|