67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
#from cam_server.pipeline.data_processing import functions, processor
|
|
|
|
#def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata=None):
|
|
# ret = processor.process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata)
|
|
# return ret
|
|
|
|
import numpy as np
|
|
from collections import OrderedDict
|
|
from cam_server.pipeline.data_processing import functions
|
|
from logging import getLogger
|
|
#import copy
|
|
|
|
from skimage.registration import phase_cross_correlation
|
|
|
|
_logger = getLogger(__name__)
|
|
|
|
#refimg = np.array([])
|
|
refimg = None
|
|
xpos = 0.0
|
|
|
|
def process_image(image, pulse_id, timestamp, x_axis, y_axis, parameters, bsdata):
|
|
|
|
global refimg
|
|
global xpos
|
|
|
|
#image = (image < 15) * (image - 15)
|
|
ret = OrderedDict()
|
|
prefix = parameters["camera_name"]
|
|
(x_profile, y_profile) = functions.get_x_y_profile(image)
|
|
_, _, x_fit_amplitude, x_fit_mean, _, _, _ = functions.gauss_fit(x_profile, x_axis)
|
|
_, _, y_fit_amplitude, y_fit_mean, _, _, _ = functions.gauss_fit(y_profile, y_axis)
|
|
x_fwhm = functions.get_fw(x_axis,x_profile)
|
|
y_fwhm = functions.get_fw(y_axis,y_profile)
|
|
intensity = x_profile.sum()
|
|
|
|
ret[prefix+":intensity"] = intensity
|
|
ret[prefix+":x_fit_mean"] = x_fit_mean
|
|
ret[prefix+":y_fit_mean"] = y_fit_mean
|
|
ret[prefix+":x_fwhm"] = x_fwhm
|
|
ret[prefix+":y_fwhm"] = y_fwhm
|
|
ret[prefix+":x_fit_amplitude"] = x_fit_amplitude
|
|
ret[prefix+":y_fit_amplitude"] = y_fit_amplitude
|
|
ret[prefix+":x_shift"] = 1.0
|
|
ret[prefix+":y_shift"] = 1.0
|
|
ret[prefix+":x_pos"] = 1.0
|
|
|
|
if isinstance(refimg, np.ndarray):
|
|
|
|
shift, error, diffphase = phase_cross_correlation(image, refimg, upsample_factor=500)
|
|
|
|
ret[prefix+":x_shift"] = float(shift[1]) + xpos
|
|
ret[prefix+":y_shift"] = float(shift[0])
|
|
#xpos = xpos + float(shift[1])
|
|
ret[prefix+":x_pos"] = xpos
|
|
|
|
else:
|
|
|
|
xpos = x_fit_mean
|
|
refimg = image * 1
|
|
ret[prefix+":x_shift"] = xpos
|
|
ret[prefix+":y_shift"] = 5232.0
|
|
|
|
#refimg = np.ndarray([])
|
|
#refimg = image * 1
|
|
|
|
return ret
|