79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
from ijutils import *
|
|
|
|
|
|
roi_center = (800, 600)
|
|
roi_radius = 600
|
|
roi = (roi_center[0] - roi_radius, roi_center[1] - roi_radius, 2* roi_radius, 2*roi_radius)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def get_image(samples = 1):
|
|
frames = []
|
|
for i in range(samples):
|
|
ip = load_image(img.image)
|
|
aux = sub_image(ip, roi[0], roi[1], roi[2], roi[3])
|
|
grayscale(aux)
|
|
frames.append(aux)
|
|
return integrate(frames)
|
|
|
|
|
|
img.backgroundEnabled=False
|
|
led_ctrl1.write(0.0)
|
|
led_ctrl2.write(0.0)
|
|
time.sleep(1.0)
|
|
|
|
background = get_image(5)
|
|
#img.setBackground(background.getBufferedImage())
|
|
#img.captureBackground(1,0)
|
|
#show_panel(img.backgroundImage)
|
|
|
|
#img.backgroundEnabled = True
|
|
|
|
led_ctrl1.write(0.40)
|
|
led_ctrl2.write(0.40)
|
|
time.sleep(1.0)
|
|
image = get_image(5)
|
|
|
|
op_image(image, background, "subtract", float_result=True, in_place=True)
|
|
|
|
|
|
show_panel(image.getBufferedImage())
|
|
|
|
invert(image)
|
|
auto_threshold(image, method = "MaxEntropy") #Tested ok: MaxEntropy, Triangle, Yen
|
|
#binary_open(aux)
|
|
(r,output) = analyse_particles(image, 250,1000,
|
|
fill_holes = True, exclude_edges = False, print_table=False,
|
|
output_image = "outlines", minCirc = 0.3
|
|
, maxCirc = 1.0)
|
|
|
|
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
|
|
|
|
|
|
print r
|
|
#show_panel(output.getBufferedImage())
|
|
|
|
#img.backgroundEnabled=False
|
|
|
|
|