This example notebook explain the use of analysis module "skbeam/core/roi" https://github.com/scikit-beam/scikit-beam/blob/master/skbeam/core/roi.py
In [1]:
import skbeam.core.roi as roi
import skbeam.core.correlation as corr
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib.ticker import MaxNLocator
from matplotlib.colors import LogNorm
import xray_vision.mpl_plotting as mpl_plot
In [2]:
interactive_mode = False
import matplotlib as mpl
if interactive_mode:
%matplotlib notebook
else:
%matplotlib inline
backend = mpl.get_backend()
cmap='viridis'
In [3]:
center = (100., 100.) # center of the rings
# Image shape which is used to determine the maximum extent of output pixel coordinates
img_shape = (200, 205)
first_q = 10.0 # inner radius of the inner-most ring
delta_q = 5.0 #ring thickness
num_rings = 7 # number of Q rings
# step or spacing, spacing between rings
one_step_q = 5.0 # one spacing between rings
step_q = [2.5, 3.0, 5.8] # differnt spacing between rings
In [4]:
# inner and outer radius for each ring
edges = roi.ring_edges(first_q, width=delta_q, spacing=one_step_q,
num_rings=num_rings)
edges
Out[4]:
In [5]:
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.rings(edges, center, img_shape)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Same spacing between rings")
im = mpl_plot.show_label_array(axes, label_array, cmap)
plt.show()
In [6]:
# inner and outer radius for each ring
edges = roi.ring_edges(first_q, width=delta_q, spacing=step_q,
num_rings=4)
print("edges when there is different spacing between rings", edges)
In [7]:
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.rings(edges, center, img_shape)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Different spacing between rings")
axes.set_xlim(50, 150)
axes.set_ylim(50, 150)
im = mpl_plot.show_label_array(axes, label_array, cmap)
plt.show()
In [8]:
# inner and outer radius for each ring
edges = roi.ring_edges(first_q, width=delta_q, num_rings=num_rings)
edges
Out[8]:
In [9]:
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.rings(edges, center, img_shape)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("There is no spacing between rings")
axes.set_xlim(50, 150)
axes.set_ylim(50, 150)
im = mpl_plot.show_label_array(axes, label_array, cmap)
plt.show()
In [10]:
center = (75, 75) # center of the rings
#Image shape which is used to determine the maximum extent of output pixel coordinates
img_shape = (150, 140)
first_q = 5.0 # inner radius of the inner-most ring
delta_q = 5.0 #ring thickness
num_rings = 4 # number of rings
slicing = 4 # number of pie slices or list of angles in radians
spacing = 4 # margin between rings, 0 by default
In [11]:
# inner and outer radius for each ring
edges = roi.ring_edges(first_q, width=delta_q, spacing=spacing,
num_rings=num_rings)
edges
Out[11]:
In [12]:
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.segmented_rings(edges, slicing, center,
img_shape, offset_angle=0)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Segmented Rings")
axes.set_xlim(38, 120)
axes.set_ylim(38, 120)
im = mpl_plot.show_label_array(axes, label_array, cmap)
plt.show()
In [13]:
slicing = np.radians([0, 60, 120, 240, 300])
slicing
Out[13]:
In [14]:
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.segmented_rings(edges, slicing, center,
img_shape, offset_angle=0)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Segmented Rings")
axes.set_xlim(38, 120)
axes.set_ylim(38, 120)
im = mpl_plot.show_label_array(axes, label_array, cmap="gray")
plt.show()
In [15]:
first_q = 0
# inner and outer radius for each ring
edges = roi.ring_edges(first_q, width=50, num_rings=1)
edges
Out[15]:
In [16]:
slicing = 10 # number of pie slices or list of angles in radians
#Elements not inside any ROI are zero; elements inside each
#ROI are 1, 2, 3, corresponding to the order they are specified in edges.
label_array = roi.segmented_rings(edges, slicing, center,
img_shape, offset_angle=0)
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Pies")
axes.set_xlim(20, 140)
axes.set_ylim(20, 140)
im = mpl_plot.show_label_array(axes, label_array, cmap)
plt.show()
In [17]:
# Image shape which is used to determine the maximum extent of output pixel coordinates
shape = (15, 26)
# coordinates of the upper-left corner and width and height of each rectangle
roi_data = np.array(([2, 2, 6, 3], [6, 7, 8, 5], [8, 18, 5, 10]),
dtype=np.int64)
#Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding
# to the order they are specified in coords.
label_array = roi.rectangles(roi_data, shape)
roi_inds, pixel_list = roi.extract_label_indices(label_array)
In [18]:
edges = [[3, 4], [5, 7], [12, 15]]
edges
Out[18]:
In [19]:
h_label_array = roi.bar(edges, (20, 25)) # Horizontal Bars
In [20]:
v_label_array = roi.bar(edges, (20, 25), horizontal=False) # Vertical Bars
In [21]:
b_label_array = roi.box((20, 25), edges)
In [22]:
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
axes[1, 0].set_title("Horizontal Bars")
im = mpl_plot.show_label_array(axes[1, 0], h_label_array, cmap)
axes[0, 1].set_title("Vertical Bars")
im = mpl_plot.show_label_array(axes[0, 1], v_label_array, cmap)
axes[1, 1].set_title("Box Rois")
im = mpl_plot.show_label_array(axes[1, 1], b_label_array, cmap)
axes[0, 0].set_title("Rectangle Rois")
im = mpl_plot.show_label_array(axes[0, 0], label_array, cmap)
plt.show()
In [23]:
label_lines= roi.lines(([0, 45, 50, 256], [56, 60, 80, 150]), (150, 250))
# plot the figure
fig, axes = plt.subplots(figsize=(6, 5))
axes.set_title("Lines")
im = mpl_plot.show_label_array(axes, label_lines, cmap)
plt.show()
In [24]:
import skbeam
print(skbeam.__version__)
In [ ]: