82 lines
2.0 KiB
Python
82 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)
|
|
|
|
|
|
#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,2)
|
|
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)
|
|
p = plot(ydata,xdata=xdata)[0]
|
|
|
|
|
|
peaks = estimate_peak_indexes(ydata, xdata, (min(ydata) + max(ydata))/2, 25.0)
|
|
print "Peak indexes: " + str(map(lambda x:xdata[x], peaks))
|
|
print "Peak values: " + str(map(lambda x:ydata[x], peaks))
|
|
|
|
|
|
for i in range(len(peaks)):
|
|
peak = xdata[peaks[i]]
|
|
p.addMarker(peak, None, "N="+str(round(peak,2)), Color(80,0,80)) |