Files
mxsc/script/CoverDetection.py
2017-06-23 15:20:53 +02:00

88 lines
2.0 KiB
Python

###################################################################################################
# Procedure to detect the cover orientation
###################################################################################################
import ch.psi.pshell.imaging.Utils.integrateVertically as integrateVertically
img.backgroundEnabled=False
line = load_image("{images}/line.png", title="Line")
line.getProcessor().setBackgroundValue(0.0)
#renderer = show_panel(line.bufferedImage)
#ip = get_image()
ip = average_frames(1000)
ip = grayscale(ip, False)
show_panel(ip.bufferedImage)
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()
"""
vals = []
for i in range (180):
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)
vals.append(sum(p))
#renderer = show_panel(op.bufferedImage)
#time.sleep(0.001)
plot(vals)
"""
#image_fft(ip)
"""
(r,output) = analyse_particles(ip, 200000,500000,
fill_holes = True, exclude_edges = False, print_table=True,
output_image = "outlines", minCirc = 0.3
, maxCirc = 1.0)
show_panel(output.bufferedImage)
"""