core.roi Module

This module contain convenience methods to generate ROI labeled arrays for simple shapes such as rectangles and concentric circles.

skbeam.core.roi.auto_find_center_rings(avg_img, sigma=1, no_rings=4, min_samples=3, residual_threshold=1, max_trials=1000)

This will find the center of the speckle pattern and the radii of the most intense rings.

Parameters
avg_img2D array

shape of the image

sigmafloat, optional

Standard deviation of the Gaussian filter.

no_ringsint, optional

number of rings

min_sampleint, optional

The minimum number of data points to fit a model to.

residual_thresholdfloat, optional

Maximum distance for a data point to be classified as an inlier.

max_trialsint, optional

Maximum number of iterations for random sample selection.

Returns
centertuple

center co-ordinates of the speckle pattern

image2D array

Indices of pixels that belong to the rings, directly index into an array

radiilist

values of the radii of the rings

skbeam.core.roi.bar(edges, shape, horizontal=True, values=None)

Draw bars defined by edges from one edge to the other of image_shape

Bars will be horizontal or vertical depending on the value of horizontal

Parameters
edgeslist

List of tuples of inner (left or top) and outer (right or bottom) edges of each bar. e.g., edges=[(1, 2), (11, 12), (21, 22)]

shapetuple

Shape of the image in which to create the ROIs e.g., shape=(512, 512)

horizontalbool, optional

True: Make horizontal bars False: Make vertical bars Defaults to True

valuesarray, optional

image pixels co-ordinates

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in edges. Has shape=`image shape`

skbeam.core.roi.box(shape, v_edges, h_edges=None, h_values=None, v_values=None)
Draw box shaped rois when the horizontal and vertical edges

are provided.

Parameters
shapetuple

Shape of the image in which to create the ROIs e.g., shape=(512, 512)

v_edgeslist

giving the inner and outer edges of each vertical bar e.g., [(1, 2), (11, 12), (21, 22)]

h_edgeslist, optional

giving the inner and outer edges of each horizontal bar e.g., [(1, 2), (11, 12), (21, 22)]

h_valuesarray, optional

image pixels co-ordinates in horizontal direction shape has to be image shape

v_valuesarray, optional

image pixels co-ordinates in vertical direction shape has to be image shape

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in edges.

skbeam.core.roi.circular_average(image, calibrated_center, threshold=0, nx=100, pixel_size=(1, 1), min_x=None, max_x=None, mask=None)

Circular average of the the image data The circular average is also known as the radial integration

Parameters
imagearray

Image to compute the average as a function of radius

calibrated_centertuple

The center of the image in pixel units argument order should be (row, col)

thresholdint, optional

Ignore counts below threshold default is zero

nxint, optional

number of bins in x defaults is 100 bins

pixel_sizetuple, optional

The size of a pixel (in a real unit, like mm). argument order should be (pixel_height, pixel_width) default is (1, 1)

min_xfloat, optional number of pixels

Left edge of first bin defaults to minimum value of x

max_xfloat, optional number of pixels

Right edge of last bin defaults to maximum value of x

maskmask for 2D data. Assumes 1 is non masked and 0 masked.

None defaults to no mask.

Returns
bin_centersarray

The center of each bin in R. shape is (nx, )

ring_averagesarray

Radial average of the image. shape is (nx, ).

See also

bad_to_nan_gen

Create a mask with np.nan entries

bin_grid

Bin and integrate an image, given the radial array of pixels Useful for nonlinear spacing (Ewald curvature)

skbeam.core.roi.extract_label_indices(labels)

This will find the label’s required region of interests (roi’s), number of roi’s count the number of pixels in each roi’s and pixels list for the required roi’s.

Parameters
labelsarray

labeled array; 0 is background. Each ROI is represented by a distinct label (i.e., integer).

Returns
label_maskarray

1D array labeling each foreground pixel e.g., [1, 1, 1, 1, 2, 2, 1, 1]

indicesarray

1D array of indices into the raveled image for all foreground pixels (labeled nonzero) e.g., [5, 6, 7, 8, 14, 15, 21, 22]

skbeam.core.roi.kymograph(images, labels, num)

This function will provide data for graphical representation of pixels variation over time for required ROI.

Parameters
imagesarray

Image stack. dimensions are: (num_img, num_rows, num_cols)

labelsarray

labeled array; 0 is background. Each ROI is represented by an integer

numint

The ROI to turn into a kymograph

Returns
kymographarray

data for graphical representation of pixels variation over time for required ROI

skbeam.core.roi.lines(end_points, shape)
Parameters
end_pointsiterable

coordinates of the starting point and the ending point of each line: e.g., [(start_x, start_y, end_x, end_y), (x1, y1, x2, y2)]

shapetuple

Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in coords. Order is (rr, cc).

skbeam.core.roi.mean_intensity(images, labeled_array, index=None)

Compute the mean intensity for each ROI in the image list

Parameters
imageslist

List of images

labeled_arrayarray

labeled array; 0 is background. Each ROI is represented by a nonzero integer. It is not required that the ROI labels are contiguous

indexint, list, optional

The ROI’s to use. If None, this function will extract averages for all ROIs

Returns
mean_intensityarray

The mean intensity of each ROI for all images Dimensions:

  • len(mean_intensity) == len(index)

  • len(mean_intensity[0]) == len(images)

indexlist

The labels for each element of the mean_intensity list

skbeam.core.roi.rectangles(coords, shape)

This function wil provide the indices array for rectangle region of interests.

Parameters
coordsiterable

coordinates of the upper-left corner and width and height of each rectangle: e.g., [(x, y, w, h), (x, y, w, h)]

shapetuple

Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in coords. Order is (rr, cc).

skbeam.core.roi.ring_edges(inner_radius, width, spacing=0, num_rings=None)

Calculate the inner and outer radius of a set of rings.

The number of rings, their widths, and any spacing between rings can be specified. They can be uniform or varied.

Parameters
inner_radiusfloat

inner radius of the inner-most ring

widthfloat or list of floats

ring thickness If a float, all rings will have the same thickness.

spacingfloat or list of floats, optional

margin between rings, 0 by default If a float, all rings will have the same spacing. If a list, the length of the list must be one less than the number of rings.

num_ringsint, optional

number of rings Required if width and spacing are not lists and number cannot thereby be inferred. If it is given and can also be inferred, input is checked for consistency.

Returns
edgesarray

inner and outer radius for each ring

skbeam.core.roi.rings(edges, center, shape)

Draw annual (ring-shaped) shaped regions of interest.

Each ring will be labeled with an integer. Regions outside any ring will be filled with zeros.

Parameters
edges: list

giving the inner and outer radius of each ring e.g., [(1, 2), (11, 12), (21, 22)]

center: tuple

point in image where r=0; may be a float giving subpixel precision. Order is (rr, cc).

shape: tuple

Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in edges.

skbeam.core.roi.roi_max_counts(images_sets, label_array)

Return the brightest pixel in any ROI in any image in the image set.

Parameters
images_setsarray

iterable of 4D arrays shapes is: (len(images_sets), )

label_arrayarray

labeled array; 0 is background. Each ROI is represented by a distinct label (i.e., integer).

Returns
max_countsint

maximum pixel counts

skbeam.core.roi.roi_pixel_values(image, labels, index=None)

This will provide intensities of the ROI’s of the labeled array according to the pixel list eg: intensities of the rings of the labeled array

Parameters
imagearray

image data dimensions are: (rr, cc)

labelsarray

labeled array; 0 is background. Each ROI is represented by a distinct label (i.e., integer).

index_listlist, optional

labels list eg: 5 ROI’s index = [1, 2, 3, 4, 5]

Returns
roi_pixlist

intensities of the ROI’s of the labeled array according to the pixel list

skbeam.core.roi.segmented_rings(edges, segments, center, shape, offset_angle=0)
Parameters
edgesarray

inner and outer radius for each ring

segmentsint or list

number of pie slices or list of angles in radians That is, 8 produces eight equal-sized angular segments, whereas a list can be used to produce segments of unequal size.

centertuple

point in image where r=0; may be a float giving subpixel precision. Order is (rr, cc).

shape: tuple

Image shape which is used to determine the maximum extent of output pixel coordinates. Order is (rr, cc).

angle_offsetfloat or array, optional

offset in radians from offset_angle=0 along the positive X axis

Returns
label_arrayarray

Elements not inside any ROI are zero; elements inside each ROI are 1, 2, 3, corresponding to the order they are specified in edges and segments

See also

ring_edges

Calculate the inner and outer radius of a set of rings.