-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More tests #3
More tests #3
Changes from 3 commits
4596895
5c91909
e276402
caeecaf
b24b5a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ | |
######################################################################## | ||
|
||
""" | ||
This module is to get informations of different region of interests(roi's). | ||
Information : the number of pixels, pixel indices, indices | ||
This module is to get information of different region of interests(roi's). | ||
Information : pixel indices, indices array | ||
""" | ||
|
||
|
||
|
@@ -62,6 +62,8 @@ | |
|
||
def rectangles(coords, shape): | ||
""" | ||
This function wil provide the indices array for rectangle region of interests. | ||
|
||
Parameters | ||
---------- | ||
coords : iterable | ||
|
@@ -214,7 +216,7 @@ def ring_edges(inner_radius, width, spacing=0, num_rings=None): | |
if num_rings != len(width): | ||
raise ValueError("num_rings does not match width list") | ||
if spacing_is_list: | ||
if num_rings != len(spacing): | ||
if num_rings-1 != len(spacing): | ||
raise ValueError("num_rings does not match spacing list") | ||
|
||
# Now regularlize the input. | ||
|
@@ -229,3 +231,87 @@ def ring_edges(inner_radius, width, spacing=0, num_rings=None): | |
edges = np.cumsum(steps).reshape(-1, 2) | ||
|
||
return edges | ||
|
||
|
||
def divide_pies(image_shape, radius, calibrated_center, | ||
num_angles, rotate='N',): | ||
""" | ||
This function will provide the indices when a circular roi | ||
is divided into pies. | ||
|
||
Parameters | ||
---------- | ||
image_shape : tuple | ||
shape of the image (detector X and Y direction) | ||
Order is (num_rows, num_columns) | ||
|
||
radius : float | ||
radius of the circle | ||
|
||
calibrated_center : tuple | ||
defining the center of the image | ||
(column value, row value) (mm) | ||
|
||
num_angles : int | ||
number of angles ring divide into | ||
angles are measured from horizontal-anti clock wise | ||
|
||
rotate : {'Y', 'N'}, optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remember to remove this. |
||
to make angles measured from vertical-anti clock wise | ||
|
||
Returns | ||
------- | ||
labels_grid : array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call this |
||
indices of the required roi's | ||
shape is ([image_shape[0], image_shape[1]]) | ||
""" | ||
angle_grid = get_angle_grid(image_shape, calibrated_center) | ||
# required angles | ||
angles = np.linspace(0, 360, num_angles) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# the indices of the bins(angles) to which each value in input | ||
# array(angle_grid) belongs. | ||
ind_grid = (np.digitize(np.ravel(angle_grid), angles, | ||
right=False)).reshape(image_shape) | ||
|
||
# radius grid for the image_shape | ||
grid_values = core.pixel_to_radius(image_shape, calibrated_center) | ||
|
||
if rotate == 'Y': | ||
ind_grid = np.rot90(ind_grid) | ||
|
||
ind_grid[grid_values > radius] = 0 | ||
|
||
labels_grid = ind_grid.reshape(image_shape) | ||
|
||
return labels_grid | ||
|
||
|
||
def get_angle_grid(image_shape, calibrated_center): | ||
""" | ||
This function will provide angle values for the whole grid | ||
from the calibrated center | ||
|
||
Parameters | ||
---------- | ||
image_shape : tuple | ||
shape of the image (detector X and Y direction) | ||
Order is (num_rows, num_columns) | ||
|
||
calibrated_center : tuple | ||
defining the center of the image | ||
(column value, row value) (mm) | ||
|
||
Returns | ||
------- | ||
angle_grid : array | ||
angle values from the calibrated center | ||
shape image_shape | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sameera2004 and I benchmarked this against trackpy's theta_mask (https://github.com/soft-matter/trackpy/blob/master/trackpy/masks.py#L40) and found theta_mask to be 30X times faster. Note that theta_mask assumes r=0 is in the center of the image, which may be the source of perf gains. |
||
yy, xx = np.mgrid[:image_shape[0], :image_shape[1]] | ||
y_ = (np.flipud(yy) - calibrated_center[0]) | ||
x_ = (xx - calibrated_center[1]) | ||
angle_grid = np.rad2deg(np.arctan2(y_, x_)) | ||
|
||
angle_grid[angle_grid < 0] = 360 + angle_grid[angle_grid < 0] | ||
|
||
return angle_grid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pie_slices(edges, slicing, center, shape, theta0=0)
whereslicing
can be an integer (slicing=8
gives 8 equal-sized slices, like a pizza) or a list of angles in degrees like[0, 70, 190]
. In either casetheta0
should be added to the resultant angles to provide an easy way to adjust the alignment.