This commit is contained in:
gac-S_Changer
2017-06-27 15:34:13 +02:00
parent 6211e795b8
commit 912a3ff63c
12 changed files with 1122 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
###################################################################################################
# Procedure to detect the cover orientation
###################################################################################################
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
img.backgroundEnabled=False
REF = (0,96,125)
line = load_image("{images}/line.png", title="Line")
line.getProcessor().setBackgroundValue(0.0)
#ip = get_image()
ip = integrate_frames(10)
ip = grayscale(ip, True)
smooth(ip)
#bandpass_filter(ip, 30, 1000)
edges(ip)
#invert(ip)
#auto_threshold(ip, method = "Default")
#auto_threshold(ip, method = "Li")
auto_threshold(ip, method = "MaxEntropy")
"""
for m in AutoThresholder.getMethods():
print m
aux = ip.duplicate()
auto_threshold(aux, method = m)
binary_fill_holes(aux, dark_background=False)
renderer = show_panel(aux.bufferedImage)
time.sleep(1.0)
"""
binary_dilate(ip, dark_background=False)
#binary_fill_holes(ip, dark_background=False)
#binary_open(ip, dark_background=Tr)
renderer = show_panel(ip.bufferedImage)
line = sub_image(line, 325, 325, 512, 512)
ip = sub_image(ip, 325, 325, 512, 512)
#op = op_fft(ip, line, "correlate")
renderer = show_panel(ip.bufferedImage)
#renderer = show_panel(op.bufferedImage)
#line.show()
ydata = []
xdata = range (0,180,1)
for i in xdata:
l = line.duplicate()
l.getProcessor().setBackgroundValue(0.0)
l.getProcessor().rotate(float(i))
op = op_fft(ip, l, "correlate")
bi = op.getBufferedImage()
p = integrateVertically(bi)
ydata.append(sum(p))
#renderer = show_panel(op.bufferedImage)
#time.sleep(0.001)
def moving_average(arr, n) :
ret = []
for i in range(len(arr)):
ret.append(mean(arr[max(i-n,0):min(i+n,len(arr)-1)]))
return ret
av = moving_average(ydata, 1)
p = plot(ydata, xdata=xdata)[0]
p.addSeries(LinePlotSeries("Moving Average"))
p.getSeries(1).setData(xdata, av)
peaks = estimate_peak_indexes(ydata, xdata, (min(ydata) + max(ydata))/2, 25.0)
left, right = min(peaks), max(peaks)
if xdata[left]<5 and xdata[right]>(xdata[-1]-5):
#del peaks[0 if ydata[right] > ydata[left] else -1]
peaks.remove(right if ydata[right] > ydata[left] else left)
peaks = sorted(peaks[:3])
peaks_x = map(lambda x:xdata[x], peaks)
peaks_y = map(lambda x:ydata[x], peaks)
print "Peaks", peaks
print "Peak indexes: " + str(peaks_x)
print "Peak values: " + str(peaks_y)
for i in range(len(peaks)):
peak = xdata[peaks[i]]
p.addMarker(peak, None, "N="+str(round(peak,2)), Color(80,0,80))
if ((peaks[i]>160) and (REF[i]<20)):
peaks[i] = peaks[i] - 180.0
print "Peaks x: " + str(peaks_x)
d = mean(arrabs(arrsub(REF, peaks_x)))
print "Angle = ", d

View File

@@ -0,0 +1,102 @@
###################################################################################################
# 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
integration_count = 10
integration_continuous = False
integration_partial = False
frames = []
roi = get_roi()
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])
last_ret = (None, None)
def detect_led(ip):
roi = get_roi()
global roi_center, roi_radius, integration_count, integration_continuous, integration_partial, frames
global count , last_ret
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)
ip = None
class MyFilter(Filter):
def process(self, image, data):
global roi_center, roi_radius, ip
ip = load_image(image)
(results,output) = detect_led(ip)
if output is not None:
invert(output)
output = pad_image(output, roi[0], 0,roi[1], 0)
op_image(ip, output, "xor")
return ip.getBufferedImage()
#Setting the filter to a source
img.setFilter(MyFilter())

View File

@@ -0,0 +1,68 @@
###################################################################################################
# Procedure to detect the puck light spots.
###################################################################################################
img.backgroundEnabled=False
led_ctrl1.write(0.0)
led_ctrl2.write(0.0)
time.sleep(0.1)
img.waitNext(100)
background = average_frames(5)
#img.backgroundImage=background.bufferedImage
#img.captureBackground(1,0)
#show_panel(img.backgroundImage)
#img.backgroundEnabled = True
led_ctrl1.write(0.40)
led_ctrl2.write(0.40)
time.sleep(0.1)
img.waitNext(100)
image = average_frames(5)
led_ctrl1.write(0.0)
led_ctrl2.write(0.0)
op_image(image, background, "subtract", float_result=True, in_place=True)
renderer = show_panel(image.getBufferedImage())
renderer.clearOverlays()
invert(image)
auto_threshold(image, method = "MaxEntropy") #Tested ok: MaxEntropy, Triangle, Yen
#binary_open(aux)
(r,output) = analyse_particles(image, 150,1000,
fill_holes = True, exclude_edges = False, print_table=False,
output_image = "outlines", minCirc = 0.3
, maxCirc = 1.0)
points = ""
npoints = 0
x=[]
y=[]
for row in range (r.counter):
if in_roi(r.getValue("XM",row), r.getValue("YM",row)):
#x, y = int(r.getValue("XM", row))+roi[0], int(r.getValue("YM", row))+roi[1]
x.append(int(r.getValue("XM", row)))
y.append(int(r.getValue("YM", row)))
points = points + " (" + str(x[-1]) + ", " + str(y[-1]) + ")"
npoints = npoints + 1
renderer.addOverlay(Crosshairs(Pen(java.awt.Color.MAGENTA), java.awt.Point(x[-1],y[-1]), java.awt.Dimension(15,15)))
print str(npoints) + " - " + points
print r
print x
print y
offset = int(math.sqrt(1000)/2)
cv = (min(x)-offset, min(y)-offset, max(x)+offset, max(y)+offset)
renderer.addOverlay(Rect(Pen(java.awt.Color.MAGENTA), java.awt.Point(cv[0], cv[1]), java.awt.Dimension(cv[2]-cv[0],cv[3]-cv[1])))
#show_panel(output.getBufferedImage())
#img.backgroundEnabled=False

View File

@@ -0,0 +1,24 @@
###################################################################################################
# Example of using ImageJ functionalities through ijutils.
###################################################################################################
from ijutils import *
import java.awt.Color as Color
#Image Loading
ip = load_image("{images}/test2.png", title="Image")
#Puck Detection
aux = grayscale(ip, in_place=False)
aux.show()
plot(get_histogram(aux))
subtract_background(aux)
threshold(aux,0,50); aux.repaintWindow()
binary_fill_holes(aux); aux.repaintWindow()
(results,output_img)=analyse_particles(aux, 10000,50000,
fill_holes = False, exclude_edges = True,print_table=True,
output_image = "outlines", minCirc = 0.0, maxCirc = 1.0)
output_img.show()

View File

@@ -0,0 +1,23 @@
###################################################################################################
# Example of using ImageJ functionalities through ijutils.
###################################################################################################
from ijutils import *
import java.awt.Color as Color
#Image Loading
ip = load_image("{images}/test2.png", title="Image")
aux = grayscale(ip, in_place=False)
aux.show()
invert(aux); aux.repaintWindow()
#gaussian_blur(aux); aux.repaintWindow()
subtract_background(aux); aux.repaintWindow()
auto_threshold(aux); aux.repaintWindow()
binary_open(aux); aux.repaintWindow()
#binary_fill_holes(aux); aux.repaintWindow()
(results,output_img)=analyse_particles(aux, 250,1000,
fill_holes = False, exclude_edges = True,print_table=True,
output_image = "outlines", minCirc = 0.7, maxCirc = 1.0)
output_img.show()