Script execution
This commit is contained in:
@@ -8,7 +8,33 @@ import java.awt.Rectangle as Rectangle
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
|
||||
|
||||
def integrate(ips, as_float=True):
|
||||
###############################################################################
|
||||
# ROI Integration
|
||||
###############################################################################
|
||||
|
||||
def integrate_roi(source, x,y, w, h):
|
||||
if source.data is None:
|
||||
source.update()
|
||||
roi = source.data.getRoi(Rectangle(x,y, w, h))
|
||||
return sum(roi.integrateHorizontally(False))
|
||||
|
||||
|
||||
|
||||
class RoiIntensity(ReadonlyRegisterBase):
|
||||
def __init__(self, name, source, x,y, w, h):
|
||||
ReadonlyRegisterBase.__init__(self, name)
|
||||
self.source=source
|
||||
self.roi = x,y, w, h
|
||||
|
||||
def doRead(self):
|
||||
x,y, w, h = self.roi
|
||||
return integrate_roi(self.source, x,y, w, h)
|
||||
|
||||
###############################################################################
|
||||
# Frame integration
|
||||
###############################################################################
|
||||
|
||||
def integrate_ips(ips, as_float=True):
|
||||
aux = None
|
||||
for i in range(len(ips)):
|
||||
if i==0:
|
||||
@@ -17,7 +43,7 @@ def integrate(ips, as_float=True):
|
||||
op_image(aux, ips[i], "add", float_result=as_float, in_place=True)
|
||||
return aux
|
||||
|
||||
def average (ips, roi=None, as_float=True):
|
||||
def average_ips (ips, roi=None, as_float=True):
|
||||
aux = integrate(ips, as_float)
|
||||
op_const(aux, "divide", float(len(ips)), in_place=True)
|
||||
return aux
|
||||
@@ -38,12 +64,16 @@ def grab_frames(source, samples, roi=None, wait_next=False, sleep=0):
|
||||
return frames
|
||||
|
||||
def average_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return average(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
return average_ips(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
|
||||
def integrate_frames(source, samples=1, roi=None, wait_next=False, sleep=0, as_float=True):
|
||||
return integrate(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
return integrate_ips(grab_frames(source, samples, roi, wait_next, sleep), as_float)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Image manipulation
|
||||
###############################################################################
|
||||
|
||||
def get_image_array(ip):
|
||||
if type(ip.getProcessor()) == ij.process.FloatProcessor:
|
||||
return ip.getProcessor().getFloatArray()
|
||||
@@ -52,16 +82,9 @@ def get_image_array(ip):
|
||||
|
||||
def open_image(file_name):
|
||||
file_name = get_context().setup.expandPath(file_name)
|
||||
return Opener().openTiff(file_name, 1)
|
||||
#return Opener().openTiff(file_name, 1)
|
||||
return Opener().openImage(file_name)
|
||||
|
||||
#Save TIFF from
|
||||
#save_image(av, "{images}/float.tif","tiff")
|
||||
|
||||
ret = grab_frames(image, 10, sleep=0.1)
|
||||
av = average(ret, None, True)
|
||||
print type(av.getProcessor())
|
||||
#db=av.getBufferedImage().getData().getDataBuffer()
|
||||
data = get_image_array(av)
|
||||
plot(data)
|
||||
|
||||
save_image(av, "{images}/float.tif","tiff")
|
||||
av = average(ret, None, False)
|
||||
save_image(av, "{images}/int.tif","tiff")
|
||||
|
||||
Reference in New Issue
Block a user