Skip to content
Snippets Groups Projects
Commit 85e535e0 authored by Loïc Le Guyader's avatar Loïc Le Guyader
Browse files

Adds function to split rois in two left-right

parent 4a15d598
Branches CHEM-BOZ
No related tags found
1 merge request!244WIP: BOZ for CHEM
Pipeline #96783 passed
......@@ -32,6 +32,7 @@ __all__ = [
'inspect_histogram',
'find_rois',
'find_rois_from_params',
'rois_split_lr',
'inspect_rois',
'compute_flat_field_correction',
'inspect_flat_field_domain',
......@@ -665,6 +666,41 @@ def find_rois_from_params(params):
return find_rois(data_mean, threshold)
def rois_split_lr(rois, left_fraction, gap):
""" Split 'n', '0' and 'p' ROIs in left and right.
Inputs
------
rois: dictionnary of rois
left_fraction: float between 0 and 1, fraction of the initial
roi width to go to the left roi
gap: in pixel, gap to insert between the left and right rois
Returns
-------
modified dictionary with additional 'n_l', 'n_r', '0_l', '0_r',
'p_l', 'p_r' rois
"""
for k in ['n', '0', 'p']:
width = rois[k]['xh'] - rois[k]['xl']
rois[k+'_l'] = {'xl': rois[k]['xl'],
'xh': rois[k]['xl'] + int(width*left_fraction-gap/2),
'yl': rois[k]['yl'],
'yh': rois[k]['yh']}
rois[k+'_r'] = {'xl': rois[k]['xl'] + int(width*left_fraction+gap/2),
'xh': rois[k]['xh'],
'yl': rois[k]['yl'],
'yh': rois[k]['yh']}
return rois
def _plot_roi(ax, roi, alpha, color):
"""Plot one ROIs"""
from matplotlib.patches import Rectangle
ax.add_patch(Rectangle((roi['xl'], 128-roi['yh']),
roi['xh'] - roi['xl'],
roi['yh'] - roi['yl'],
alpha=alpha, color=color))
def inspect_rois(data_mean, rois, threshold=None, allrois=False):
"""Find rois from 3 beams configuration from mean module image.
......@@ -705,22 +741,23 @@ def inspect_rois(data_mean, rois, threshold=None, allrois=False):
vmax=np.percentile(data_mean[:, :256], 99))
main_ax.set_aspect('equal')
from matplotlib.patches import Rectangle
roi = rois['n']
main_ax.add_patch(Rectangle((roi['xl'], 128-roi['yh']),
roi['xh'] - roi['xl'],
roi['yh'] - roi['yl'],
alpha=0.3, color='b'))
roi = rois['0']
main_ax.add_patch(Rectangle((roi['xl'], 128-roi['yh']),
roi['xh'] - roi['xl'],
roi['yh'] - roi['yl'],
alpha=0.3, color='g'))
roi = rois['p']
main_ax.add_patch(Rectangle((roi['xl'], 128-roi['yh']),
roi['xh'] - roi['xl'],
roi['yh'] - roi['yl'],
alpha=0.3, color='r'))
if 'n_l' in rois:
_plot_roi(main_ax, rois['n_l'], 0.3, 'b')
_plot_roi(main_ax, rois['n_r'], 0.3, 'b')
else:
_plot_roi(main_ax, rois['n'], 0.3, 'b')
if '0_l' in rois:
_plot_roi(main_ax, rois['0_l'], 0.3, 'g')
_plot_roi(main_ax, rois['0_r'], 0.3, 'g')
else:
_plot_roi(main_ax, rois['0'], 0.3, 'g')
if 'p_l' in rois:
_plot_roi(main_ax, rois['p_l'], 0.3, 'r')
_plot_roi(main_ax, rois['p_r'], 0.3, 'r')
else:
_plot_roi(main_ax, rois['p'], 0.3, 'r')
x.plot(Xs, pX)
x.invert_yaxis()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment